Authentication and Authorization 2- Registering a new User

On postman I’m trying to post “_id”, “name” and “email” properties on my http://localhost:3900/api/users, but I keep getting
“500 internal server error.”

Is anyone else having this problem? And what did I do wrong???

here’s my users.js code:

const auth = require("…/middleware/auth");

const bcrypt = require(“bcrypt-nodejs”);

const _ = require(“lodash”);

const { User, validate } = require("…/models/user");

const express = require(“express”);

const router = express.Router();

router.get("/me", auth, async (req, res) => {

const user = await User.findById(req.user._id).select("-password");


});"/", async (req, res) => {

const { error } = validate(req.body);

if (error) return res.status(400).send(error.details[0].message);

let user = await User.findOne({ email: });

if (user) return res.status(400).send(“User already registered.”);

user = new User(_.pick(req.body, [“name”, “email”, “password”]));

const salt = await bcrypt.genSalt(10);

user.password = await bcrypt.hash(user.password, salt);


const token = user.generateAuthToken();


.header("x-auth-token", token)

.send(_.pick(user, ["_id", "name", "email"]));


module.exports = router;

Okay I think I figured it out. bcrypt-nodejs is no longer active Instead use bcryptjs

Plus I upgraded my genSalt and hash code:

 bcrypt.genSalt(10, function (_err, salt) {

        bcrypt.hash(, salt, function (_err, hash) {

       // Store hash in your password DB.

       user.password = hash;