1

I am trying to start my node js server on my windows machine. On my ubuntu everything works fine and it starts up however on windows i get the following error:

 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) 

The auth.js looks like this:

 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; }; 

And my node modules are:

enter image description here

Can anyone tell me what might be the problem?

2
  • If I recall correctly, bcrypt needs VisualStudio to be installed. This is also noted in the package description. Commented Mar 9, 2015 at 14:24
  • I have VisualStudio already installed. Commented Mar 9, 2015 at 14:29

2 Answers 2

3

Did you copy the node_modules directory from your Ubuntu machine? You need to exclude that directory from your copy (and I'd advise you add this directory to your .gitignore file) because it's very likely the module you're trying to use was compiled for the Linux system.

If you exclude the directory and run npm install inside that directory on the Windows server, all of your modules including bcrypt will be re-generated to work with Windows.

Sign up to request clarification or add additional context in comments.

Comments

1

Your issue is that the node_modules you are using rely on native code that cannot be ported between different platforms.

Usually it is not a good practice to share the node_modules folder. Instead share only the package dependency declarations and each developer will have to call the npm install to be able to work on the project.

This ensures that everyone will have the packages installed that work on their platform.

As you can see bcrypt depends on node-gyp , a tool used for compiling native addons. So that is in your case one of the sources of your problem

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.