我正在尝试使用post请求将用户保存到mongodb数据库,如下所示,但我收到错误bcrypt错误:需要数据和哈希参数.这是一个非常简单的代码设置但我无法弄清楚它有什么问题.车型/ users.js
const mongoose = require('mongoose');
const bcrypt = require('bcrypt');
const confic = require('../models/users');
// User schema
const UserSchema = mongoose.Schema({
name: {
type: String,
},
email: {
type: String,
required: true
},
username:{
type: String,
required: true
},
password: {
type: String,
required: true
}
});
const User = module.exports = mongoose.model('User', UserSchema);
module.exports.getUserById = function(id,callback){
User.findById(id,callback);
}
module.exports.getUserByUsername = function(username,callback){
const query = {username:username}
User.findOne(query,callback);
}
module.exports.addUser= function (newUser, callback) {
bcrypt.genSalt(10,(err,salt) => {
bcrypt.hash(newUser.password, salt , (err, …Run Code Online (Sandbox Code Playgroud)