Im trying to create simple login app with MERN stack and i have an issue while using bcrypt to hash my password.


const mongoose = require("mongoose");
const express = require("express");
const cors = require("cors");
const passport = require("passport");
const passportLocal = require("passport-local").Strategy;
const cookieParser = require("cookie-parser");
const bcrypt = require("bcrypt");
const session = require("express-session");
const bodyParser = require("body-parser");
const app = express();
const User = require("./user")

      useNewUrlParser: true,
      useUnifiedTopology: true,
    () => {
        console.log("Mongoose Is Connected");
// Middleware
app.use(bodyParser.urlencoded({ extended: true }));
    origin: "http://localhost:3000", // <-- location of the react app were connecting to
    credentials: true,
    secret: "secretcode",
    resave: true,
    saveUninitialized: true,


app.post('/login',(req,res,next) => {
   passport.authenticate("local",(err,user,info) =>{
       if (err) throw err
       if(!user) res.send("No user with given login")
       else {
           req.logIn(user, (err) => {
               if (err) throw err
               res.send("Succesfully Authenticated")

app.post("/register", (req, res) => {
    User.findOne({ username: req.body.username }, async (err, doc) => {
      if (err) throw err;
      if (doc) res.send("User Already Exists");
      if (!doc) {
        const hashedPassword = bcrypt.hashSync(req.body.password, 10);
        const newUser = new User({
          username: req.body.username,
          password: hashedPassword,
        await newUser.save();
        res.send("User Created");
app.get('/user',(req,res) => {


app.listen(4000, () => {
    console.log("Server Has Started");


const user = new mongoose.Schema({
    username: String,
    password: String,

module.exports = mongoose.model("User",user)

My postman post request on http://localhost:4000/register


I have this error message in console when im testing my register route using postman and i cant get any response.

(node:5452) UnhandledPromiseRejectionWarning: Error: data and salt arguments required
    at Object.hashSync (C:UsersPCDesktopprojectsmern_loginbackendnode_modulesbcryptbcrypt.js:91:15)
    at C:UsersPCDesktopprojectsmern_loginbackendserver.js:64:39
    at C:UsersPCDesktopprojectsmern_loginbackendnode_modulesmongooselibmodel.js:4866:16
    at C:UsersPCDesktopprojectsmern_loginbackendnode_modulesmongooselibmodel.js:4866:16
    at C:UsersPCDesktopprojectsmern_loginbackendnode_modulesmongooselibhelperspromiseOrCallback.js:24:16   
    at C:UsersPCDesktopprojectsmern_loginbackendnode_modulesmongooselibmodel.js:4889:21
    at C:UsersPCDesktopprojectsmern_loginbackendnode_modulesmongooselibquery.js:4399:11
    at C:UsersPCDesktopprojectsmern_loginbackendnode_moduleskareemindex.js:136:16
    at processTicksAndRejections (internal/process/task_queues.js:79:11)
(node:5452) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:5452) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

I don’t know what am i doing wrong im simply trying to asynchronously call hash method to hash my password.