javascript - 无法设置未定义的属性“addUser”
问题描述
运行我的节点 js 程序时出错。
这是错误日志
TypeError: Cannot set property 'addUser' of undefined
at Object.<anonymous> (C:\Users\Noman.Matin\Desktop\mbk\angularProj3MeanAuth\models\user.js:39:26)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous>
在运行这些属性时
mongoose.exports.getUserById = function (id, callback) {
User.findById(id, callback);
}
mongoose.exports.getUserByUsername = function (username, callback) {
const query = {
username: username
};
User.findOne(query, callback);
}
mongoose.exports.addUser = function (newUser, callback) {
bcrypt.genSalt(10, (err, salt) => {
bcrypt.hash(newUser.password, salt, (err, hash) => {
if (err) throw err;
newUser.password = hash;
newUser.save(callback);
})
})
}
解决方案
推荐阅读
- android - Android DFM 动态 FeatureModule 资源 NotFoundException
- asp.net - 在 pdf 中渲染和生成时日语格式错误
- php - 为什么无法通过 PhpOffice\PhpSpreadsheet 读取 csv 文件?
- python - 如何在 Tkinter Python 中的许多按钮上应用悬停效果?
- java - 为什么我在节点末尾插入空指针异常?
- mysql - MySQL 数据库在尝试使用 Persistent Volume Claim 克隆功能时丢失
- c# - SQL中带有条件“and”的嵌套If语句
- angular - 依赖嵌套的 observables
- vue.js - Vue路由器链接类绑定活动类
- redis - redis-cli 交互模式:如何使用 --bigkeys