This module contains header-only C++ wrapper classes which simplify the use of the C based N-API provided by Node.js when using C++. It provides a C++ object model and exception handling semantics with low overhead.
N-API is an ABI stable C interface provided by Node.js for building native addons. It is independent from the underlying JavaScript runtime (e.g. V8 or ChakraCore) and is maintained as part of Node.js itself. It is intended to insulate native addons from changes in the underlying JavaScript engine and allow modules compiled for one version to run on later versions of Node.js without recompilation.
The node-addon-api
module, which is not part of Node.js, preserves the benefits
of the N-API as it consists only of inline code that depends only on the stable API
provided by N-API. As such, modules built against one version of Node.js
using node-addon-api should run without having to be rebuilt with newer versions
of Node.js.
As new APIs are added to N-API, node-addon-api must be updated to provide wrappers for those new APIs. For this reason node-addon-api provides methods that allow callers to obtain the underlying N-API handles so direct calls to N-API and the use of the objects/methods provided by node-addon-api can be used together. For example, in order to be able to use an API for which the node-add-api does not yet provide a wrapper.
APIs exposed by node-addon-api are generally used to create and manipulate JavaScript values. Concepts and operations generally map to ideas specified in the ECMA262 Language Specification.
- Setup
- API Documentation
- Examples
- Tests
- More resource and info about native Addons
- Code of Conduct
- Contributors
- License
(See CHANGELOG.md for complete Changelog)
The following is the documentation for node-addon-api (NOTE: still a work in progress as its not yet complete).
- Basic Types
- Error Handling
- Object Lifetime Management
- Working with JavaScript Values
- Memory Management
- Async Operations
- Promises
Are you new to node-addon-api? Take a look at our examples
- Hello World
- Pass arguments to a function
- Callbacks
- Object factory
- Function factory
- Wrapping C++ Object
- Factory of wrapped object
- Passing wrapped object around
To run the node-addon-api tests do:
npm install
npm test
Take a look and get inspired by our test suite
Name | GitHub link |
---|---|
Anna Henningsen | addaleax |
Arunesh Chandra | aruneshchandra |
Benjamin Byholm | kkoopa |
Gabriel Schulhof | gabrielschulhof |
Hitesh Kanwathirtha | digitalinfinity |
Jason Ginchereau | jasongin |
Michael Dawson | mhdawson |
Nicola Del Gobbo | NickNaso |
Sampson Gao | sampsongao |
Taylor Woll | boingoing |
Licensed under MIT