- Node.js v10 or higher (for N-API v3+)
Follow the installation instructions on the node-gyp package.
For Windows, Node.js allow you to install build tools at installation (be sure to get the checkbox).
When everything is setup, just run in order:
$ npx node-gyp configure
$ npx node-gyp build
The configure command will setup the default project configuration and download requiring Node.js headers (if they are missing). Only re-run this command if you are updating binding.gyp
file.
The build command run the compiler chain.
All projects commands are described here (all N-API projects must has these commands):
command | description |
---|---|
npm run prebuilds | Generate N-API prebuilds |
npm run build | Run node-gyp configure and build |
To download and/or update N-API headers we created our own binary tool.
$ napihead --help
# or
$ npx napi-headers --help
N-API headers must be installed at the root of the project in the ./include directory.
A binding.gyp file describes the configuration to build your module, in a JSON-like format. This file gets placed in the root of your package, alongside package.json.
A barebones gyp file appropriate for building a Node.js addon could look like:
{
"targets": [
{
"target_name": "windrive",
"sources": [
"windrive.cpp"
],
"include_dirs": [
"include",
"<!@(node -p \"require('node-addon-api').include\")"
],
"dependencies": [
"<!(node -p \"require('node-addon-api').gyp\")"
],
"defines": ["NAPI_DISABLE_CPP_EXCEPTIONS"],
"cflags!": [ "-fno-exceptions" ],
"cflags_cc!": [ "-fno-exceptions" ],
"msvs_settings": {
"VCCLCompilerTool": {
"ExceptionHandling": 1
}
}
}
]
}
Useful links:
All SlimIO N-API projects must be configured with the type NAPI and the right target. Example with the Windrive manifest:
name = "windrive"
version = "1.5.0"
platform = "Windows"
type = "NAPI"