我正在尝试在我的Windows机器上启动node js
服务器。在我的ubuntu上一切正常,它启动但在Windows上我得到以下错误:
c:\xampp\htdocs\learningbankapi\src\node_modules\bcrypt\node_modules\bindings\bindings.js:79
throw e
^
Error: no errorc:\xampp\htdocs\learningbankapi\src\node_modules\bcrypt\build\Release\bcrypt_lib.node
at Error (native)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at bindings (c:\xampp\htdocs\learningbankapi\src\node_modules\bcrypt\node_modules\bindings\bindings.js:74:15)
at Object.<anonymous> (c:\xampp\htdocs\learningbankapi\src\node_modules\bcrypt\bcrypt.js:3:35)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (c:\xampp\htdocs\learningbankapi\src\auth.js:2:14)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
auth.js
看起来像这样:
var jwt = require('jwt-simple');
var bcrypt = require('bcrypt');
// Route: /login
module.exports = function (express, sequelize, router) {
var DataTypes = require("sequelize");
var User = sequelize.define('user', {
id: DataTypes.INTEGER,
username: DataTypes.STRING,
password: DataTypes.STRING,
organization_id: DataTypes.INTEGER,
user_type_id: DataTypes.INTEGER,
division_id: DataTypes.INTEGER
}, {
freezeTableName: true,
instanceMethods: {
retrieveByNamePassword: function (username, onSuccess, onError) {
User.find({include: [{ all: true }],where: {username: username}}, {})
.then(onSuccess).catch(onError);
}
}
}
),
Division = sequelize.define('division', {
id: DataTypes.INTEGER,
organization_id: DataTypes.INTEGER,
location_id: DataTypes.INTEGER,
name: DataTypes.STRING
}, {freezeTableName: true}),
Profile = sequelize.define('profile', {
user_id: DataTypes.INTEGER,
firstname: DataTypes.STRING,
lastname: DataTypes.STRING,
address: DataTypes.STRING,
phone: DataTypes.STRING,
cpr: DataTypes.STRING,
description: DataTypes.STRING
}, {freezeTableName: true}),
Title = sequelize.define('title', {
id: DataTypes.INTEGER,
name: DataTypes.STRING,
organization_id: DataTypes.INTEGER
}, {freezeTableName: true});
User.belongsTo(Division,{foreignKey: 'division_id'});
User.hasOne(Profile, {foreignKey: 'user_id'});
User.belongsTo(Title, {foreignKey:'title_id'});
router.route('/login')
.post(function (req, res) {
var user = User.build();
var username = req.body.username || '';
var password = req.body.password || '';
if (username == '' || password == '') {
res.status(401);
res.json({
"status": 401,
"message": "Invalid credentials"
});
return;
}
var salt = bcrypt.genSaltSync(10);
var hash = bcrypt.hashSync(password, salt);
user.retrieveByNamePassword(username, function (users) {
var i = 0;
if (bcrypt.compareSync(password,users.password)) {
// If authentication is success, we will generate a token
// and dispatch it to the client
res.json(genToken(users));
return;
} else {
// If authentication fails, we send a 401 back
res.status(401);
res.json({
"status": 401,
"message": "Invalid credentials"
});
return;
}
}, function (error) {
res.status(401);
res.json({
"status": 401,
"message": "Invalid credentials"
});
return;
});
});
var genToken = function(user) {
var expires = expiresIn(7); // 7 days
var token = jwt.encode({
exp: expires,
user_id: user.id,
organization_id: user.organization_id,
user_type_id: user.user_type_id,
division_id: user.division_id
}, require('./config/secret')());
return {
token: token,
expires: expires,
user: user
};
};
var expiresIn = function(numDays) {
var dateObj = new Date();
return dateObj.setDate(dateObj.getDate() + numDays);
};
return router;
};
我的节点模块是:
有谁能告诉我可能是什么问题?
答案 0 :(得分:3)
您是否从Ubuntu计算机上复制了node_modules
目录?您需要从副本中排除该目录(我建议您将此目录添加到.gitignore
文件中),因为您尝试使用的模块很可能是为Linux系统编译的。
如果您排除目录并在Windows服务器上的该目录中运行npm install
,则将重新生成包括bcrypt
在内的所有模块以与Windows一起使用。
答案 1 :(得分:1)