https://github.com/ajihyf/node-addon-api-helper
A more convenient, type-safe and boilerplate-less way to write Node.js C++ addons.
https://github.com/ajihyf/node-addon-api-helper
cpp n-api napi node-addon-api
Last synced: 11 months ago
JSON representation
A more convenient, type-safe and boilerplate-less way to write Node.js C++ addons.
- Host: GitHub
- URL: https://github.com/ajihyf/node-addon-api-helper
- Owner: ajihyf
- License: mit
- Created: 2022-04-13T11:43:12.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2024-03-26T11:10:59.000Z (almost 2 years ago)
- Last Synced: 2025-02-26T09:38:54.653Z (about 1 year ago)
- Topics: cpp, n-api, napi, node-addon-api
- Language: C++
- Homepage:
- Size: 154 KB
- Stars: 15
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# node-addon-api-helper
[](https://www.npmjs.com/package/node-addon-api-helper)
[](https://github.com/ajihyf/node-addon-api-helper/actions/workflows/ci.yml)
[](https://github.com/ajihyf/node-addon-api-helper/actions/workflows/lint.yml)

[](https://github.com/ajihyf/node-addon-api-helper/blob/main/LICENSE)



Based on [node-addon-api](https://github.com/nodejs/node-addon-api), **node-addon-api-helper(naah)** provides a more convenient, type-safe and boilerplate-less way to write Node.js C++ addons.
Features:
- Automatically transform values between JavaScript and C++
- Automatically register exports
- Class binding (with inheritance)
- Custom object type
- Thread safe function
- Create async work and return promise
- Can be used together with original node-addon-api, no need to rewrite all
- Pure header, can be easily integrated
## QuickStart
```bash
npm install node-addon-api node-addon-api-helper
```
Add following content to your GYP file.
```gyp
{
'include_dirs': [
"
uint32_t add(uint32_t a, uint32_t b) {
return a + b;
}
NAAH_REGISTRATION {
naah::Registration::Function("add");
}
NAAH_EXPORT
```
## Documentation
- [Exports](./doc/exports.md)
- [Function](./doc/function.md)
- [Object](./doc/object.md)
- [Class](./doc/class.md)
- [Mix with node-addon-api](./doc/mix_with_napi.md)
- [Thread Safe Function](./doc/thread_safe_function.md)
- [Async Work](./doc/async_work.md)
- [Error Handling](./doc/error_handling.md)
## Examples
See `naah` directories in the [fork of node-addon-examples](https://github.com/ajihyf/node-addon-examples) for examples.
## Thanks
- Based on [node-addon-api](https://github.com/nodejs/node-addon-api).
- Inspired by [napi-rs](https://napi.rs), [emscripten](https://emscripten.org/) and [nbind](https://github.com/charto/nbind).