| Node-API version |
Supported In |
| 10 |
v22.14.0+, 23.6.0+ and all later versions |
| 9 |
v18.17.0+, 20.3.0+, 21.0.0 and all later versions |
| 8 |
v12.22.0+, v14.17.0+, v15.12.0+, 16.0.0 and all later versions |
| 7 |
v10.23.0+, v12.19.0+, v14.12.0+, 15.0.0 and all later versions |
| 6 |
v10.20.0+, v12.17.0+, 14.0.0 and all later versions |
| 5 |
v10.17.0+, v12.11.0+, 13.0.0 and all later versions |
| 4 |
v10.16.0+, v11.8.0+, 12.0.0 and all later versions |
| 3 |
v6.14.2*, 8.11.2+, v9.11.0+*, 10.0.0 and all later versions |
| 2 |
v8.10.0+*, v9.3.0+*, 10.0.0 and all later versions |
| 1 |
v8.6.0+**, v9.0.0+*, 10.0.0 and all later versions |
\* Node-API was experimental.
\*\* Node.js 8.0.0 included Node-API as experimental. It was released as
Node-API version 1 but continued to evolve until Node.js 8.6.0. The API is
different in versions prior to Node.js 8.6.0. We recommend Node-API version 3 or
later.
Each API documented for Node-API will have a header named `added in:`, and APIs
which are stable will have the additional header `Node-API version:`.
APIs are directly usable when using a Node.js version which supports
the Node-API version shown in `Node-API version:` or higher.
When using a Node.js version that does not support the
`Node-API version:` listed or if there is no `Node-API version:` listed,
then the API will only be available if
`#define NAPI_EXPERIMENTAL` precedes the inclusion of `node_api.h`
or `js_native_api.h`. If an API appears not to be available on
a version of Node.js which is later than the one shown in `added in:` then
this is most likely the reason for the apparent absence.
The Node-APIs associated strictly with accessing ECMAScript features from native
code can be found separately in `js_native_api.h` and `js_native_api_types.h`.
The APIs defined in these headers are included in `node_api.h` and
`node_api_types.h`. The headers are structured in this way in order to allow
implementations of Node-API outside of Node.js. For those implementations the
Node.js specific APIs may not be applicable.
The Node.js-specific parts of an addon can be separated from the code that
exposes the actual functionality to the JavaScript environment so that the
latter may be used with multiple implementations of Node-API. In the example
below, `addon.c` and `addon.h` refer only to `js_native_api.h`. This ensures
that `addon.c` can be reused to compile against either the Node.js
implementation of Node-API or any implementation of Node-API outside of Node.js.
`addon_node.c` is a separate file that contains the Node.js specific entry point
to the addon and which instantiates the addon by calling into `addon.c` when the
addon is loaded into a Node.js environment.
```c
// addon.h
#ifndef _ADDON_H_
#define _ADDON_H_
#include