This is a project template for N-API addon. To create a new project based on this template using degit:
npx degit Phamier/napi-addon-template your-napi-project
cd your-napi-project
Note that you will need to have Node.js installed.
Installing the depedencies.
npm install
npm install
automatically builds your addon after installing dependencies. There is no need to do anything else.
If you modify binding.gyp
or add new source files (src/*.cpp
), you should run ...
npm run rebuild:dev
If you modify an existing source file, npm run build:dev
will do the job.
npm run build:dev
Also there is a cleaning command...
npm run clean
You can add declarations to index.d.ts
with JSDoc documentation comments for improved Intellisence and documentaion. Example:
/**
* Hello World function
* @returns {string} "HelloWorld"
*/
export function helloWorld(): string;
If you are using Microsoft C/C++ extension, you can add custom includePath
for your project by modifying c_cpp_properties.json
:
"configurations": [{
...
"includePath": [
"${workspaceFolder}/node_modules/node-addon-api/",
"${workspaceFolder}/include/**",
"/usr/local/include/**"
],
...
Note: this method was proposed by Arul R. Basically, this template is an improved version his and I'm using the same debugging method as he does. Check out his blog post on meduza.com for more information. I will only provide my launch.json
and tasks.json
files.
launch.json
:
{
"version": "0.2.0",
"configurations": [
{
"type":"lldb",
"request": "launch",
"name": "Debug",
"preLaunchTask": "npm rebuild",
"program": "npm",
"args": "run test"
}
]
}
tasks.json
:
{
"version" : "2.0.0",
"tasks": [
{
"type": "npm",
"script": "rebuild:dev",
"problemMatcher": [],
"label": "npm rebuild",
"detail": "node-gyp rebuild --debug"
}
]
}
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.