Node.js gyp

 Node-gyp is a cross platform tool written in Node.js. It is helpful for compiling add-on modules for Node.js using command-line. Whatever the version on your system, multiple versions of Node.js are supported. Node-gyp downloads the necessary development files or headers for your Node.js version. Node-gyp build commands will work on any supported platforms and it supports the targeting of different versions of Node.js. Using npm you can install node-gyp.

$ npm install -g node-gyp

If your OS is unix you need to install Python v2.7/v3.5/v3.6/v3.7/v3.8, make, C/C++ compiler toolchain. If your OS is Mac then you you should have Python v2.7/v3.5/v3.6/v3.7/v3.8 and Xcode. Install Xcode Command Line Tool and go to menu->Xcode ->Open Developer Tool->More Developer Tool. It will install clang, clang ++ and make.

If your OS is Windows, install the current version of Python. Using Microsoft’s windows-build-tools in cmd type npm install --global --production windows-build-tools. This will install required tools and configurations.

Using node-gyp

Go to your native addon’s root directory using cd command. Create the right project build files for the current platform using configure.


$ node-gyp configure


Auto-detection for Visual C++ build tools 2015 fails so --msvs_version=2015 needs to be added.


$ node-gyp configure --msvs_version=2015


Invoke build command.


$ node-gyp build


The .node binding files are compiled now. It will be in build/Debug or build/Release/ depending on your build mode. Now require a  .node file with Node.js and run the tests. A binding.gyp file describes the configuration to build your module like JSON format. It will be in the root of your package.