How to Build node-gyp to Run bcrypt on Windows

Trying to install the node-package bcrypt on windows can be a lot of pain.
I’ve tried it on four different systems; one time it worked like a charm but the other times I had to search a lot to solve several problems.

Mostly those problems were caused by the necessary package node-gyp that couldn't be built.
This is why I decided to write a step by step guide for dummies (esp. for me) to handle that issue.

node-gyp is a dependency of a lot of packages (full list here)
If you had problems installing them this guide may also be helpful for you.

Prerequisites

  • Node and Python both should be installed as x86
  • You will need Python v2.7.3 (Python v3.x.x is not supported)
  • You will need to add Python as an Environment Variable (How to)
  • You have to install Visual Studio 2013 with C++ Tools (DownloadPage; free Express Version)

Some of this instructions you will also find on the node-gyp readme.

How to Add Python as Environment Variable

The easiest way to achieve that is during a custom installation.
Here you should select the feature called Add python.exe to Path
Python Custom Setup

Install node-gyp

run npm install -g node-gyp

If you have multiple versions of Python installed you should define which Python version node-gyp has to use: node-gyp --python /path/to/python2.7

Configure node-gyp

Before you can compile node-gyp you have to set up a JSON-like file called binding.gyp.

In our example we try to set up the bindings for bcrypt.
So we use a working demo from this git repository.
Just copy the src folder and the .gyp file to your root of your package alongside the package.json file.

In the node-gyp wiki you can find a lot of examples for other bindings.

run node-gyp configure now and a build directory will be created containing a .sln and a .vcxproj file.
build files

Build node-gyp

All you have to do now is to run node-gyp build.
If no errors occurred you've made it now.

If there are any troubles by now the reason might be that you've installed multiple versions of Visual Studio.
To build it manually you should open the binding.sln with Visual Studio.
In your Solution Explorer do a rightclick to the main project and open the properties.

Property Page Navigate to the Plattform Toolset property (see picture) and select Visual Studio 2013.
Apply your changes and rebuild your library via rightclick inside your Solution Explorer.

Some node packages depending on node-gyp run a node-gyp rebuild by default during their installation. This will cause that your Settings for the binding.sln will be undone.

To specify wich version of Visual Studio you want to run during this installation you have to use something like this npm install —msvs_version=2013

This should do the job.

I hope you found this article helpful. Let me know if it was solving a problem for you.

Explore the Library

Find interesting tutorials and solutions for your problems.