On this page

Building a native Node.js addon requires compiling C/C++ source code into a binary .node file that Node.js can load at runtime. This section covers the build tools available to you and the trade-offs between them.

There are two broad strategies for shipping a native addon:

Compile on the user's machine - When a user runs npm install, the build tool compiles your C/C++ source on their system. This is simple to set up but requires every user to have a working C/C++ toolchain installed.

Distribute pre-built binaries - You compile binaries for each supported platform and architecture ahead of time and upload them somewhere users can download. Users who download a matching binary skip the compilation step entirely; others fall back to compiling locally.

  • node-gyp - the default build tool bundled with npm; uses Google's GYP format and is nearly universally supported in the Node ecosystem
  • CMake.js - a CMake-based alternative, well-suited for projects that already use CMake
  • node-pre-gyp - a layer on top of node-gyp for distributing pre-built binaries via Amazon S3
  • prebuild - an alternative pre-build tool that publishes binaries as GitHub Releases