node-gyp
Node.js native addon build tool
A command-line tool that compiles C and C++ native addons for Node.js, letting your JavaScript app use low-level system features that plain JavaScript cannot reach.
node-gyp is a command-line tool that compiles native addons for Node.js. A native addon is a piece of code written in C or C++ that Node.js can load and run directly, giving programs access to low-level system features that plain JavaScript cannot reach. node-gyp takes care of the compilation step so that developers do not have to manage that process by hand.
Before using it, you need a few system tools already installed. On Linux and macOS those are Python, make, and a C++ compiler. On Windows you need Python plus the Visual C++ build tools that come with Visual Studio. Once those are in place, you install node-gyp via npm like any other package.
The typical workflow has three steps. First you run the configure command inside your addon folder, which reads a file called binding.gyp and generates the platform-appropriate build files. Then you run the build command, which compiles the code. The result is a .node file that your Node.js application can load. There is also a rebuild command that combines both steps, and a clean command to remove previous build output.
The binding.gyp file is a JSON-like configuration file that sits alongside package.json at the root of your addon project. It tells node-gyp the name of your target and which source files to compile. The format is flexible enough to handle complex multi-file projects, though a minimal addon only needs a target name and a list of source files.
node-gyp works on all major platforms with the same commands, and it supports building against different versions of Node.js, including third-party runtimes such as Electron that ship their own headers.
Where it fits
- Compile a C++ native addon so a Node.js app can call low-level system APIs that JavaScript cannot access.
- Build native Node.js modules that work across Windows, macOS, and Linux using the same commands.
- Compile addons against a specific Node.js version or an Electron runtime for desktop app compatibility.
- Set up a build pipeline that automatically compiles native dependencies when a user runs npm install.