首页 > 解决方案 > 无法设置未定义的属性“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);
    })
  })
}

标签: javascriptnode.jsnodesmonodevelopnode-modules

解决方案


推荐阅读