Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Node.JS send the Post request through post displayed {} Node Js

kobi

New Coder
i am creating a new user along with hash password. i ran into the problem i got the error was test trough post displayed {} using NodeJS. what i tried so far i attached below.please anyone solve the error

userController
JavaScript:
const bcrypt = require('bcrypt');

const saveCustomer = async(req,res)=>{
   

        try {
     
        const hashedPassword =  bcrypt.hash(req.body.password); // 10 is the saltRounds

        const user = new userModel({
            name: req.body.name,
            address: req.body.address,
            username: req.body.username,
            password: hashedPassword,
           


        });


        await user.validate(); // Validate the input data
   
        await user.save();
        res.status(201).send({
          status: true,
          message: "user Created!!!!!!!!!!!!!!!!"
        });
   
      } catch (error) {
        res.status(400).send(error);
      }

}


[B]User.js[/B]
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var userSchema = new Schema({
    name: {
        type: String,
        required: true
    },
    address: {
        type: String,
        required: true
    },
    username: {
        type: String,
        required: true
    },
    password: {
        type: String,
        required: true
    }
});
module.exports = mongoose.model('users', userSchema);
 
Last edited by a moderator:
i am creating a new user along with hash password. i ran into the problem i got the error was test trough post displayed {} using NodeJS. what i tried so far i attached below.please anyone solve the error

userController

const bcrypt = require('bcrypt');

const saveCustomer = async(req,res)=>{


try {

const hashedPassword = bcrypt.hash(req.body.password); // 10 is the saltRounds

const user = new userModel({
name: req.body.name,
address: req.body.address,
username: req.body.username,
password: hashedPassword,



});


await user.validate(); // Validate the input data

await user.save();
res.status(201).send({
status: true,
message: "user Created!!!!!!!!!!!!!!!!"
});

} catch (error) {
res.status(400).send(error);
}

}


User.js
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var userSchema = new Schema({
name: {
type: String,
required: true
},
address: {
type: String,
required: true
},
username: {
type: String,
required: true
},
password: {
type: String,
required: true
}
});
module.exports = mongoose.model('users', userSchema);
Hi there,
What error message are you getting?
 

New Threads

Buy us a coffee!

Back
Top Bottom