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
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: