{"$schema":"https://doc-kit.nodejs.org/schemas/api-doc/1.0.0.json","id":"n-api","path":"/n-api","type":"misc","module":null,"title":"Node-API","introducedIn":"v8.0.0","sourceLink":null,"stability":{"index":"2","description":"Stable"},"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"Node-API (formerly N-API) is an API for building native Addons. It is\nindependent from the underlying JavaScript runtime (for example, V8) and is\nmaintained as part of Node.js itself. This API will be Application Binary\nInterface (ABI) stable across versions of Node.js. It is intended to insulate\naddons from changes in the underlying JavaScript engine and allow modules\ncompiled for one major version to run on later major versions of Node.js without\nrecompilation. The [ABI Stability](https://nodejs.org/learn/modules/abi-stability) guide provides a more in-depth explanation.\n\nAddons are built/packaged with the same approach/tools outlined in the section\ntitled [C++ Addons](addons.html). The only difference is the set of APIs that are used by\nthe native code. Instead of using the V8 or [Native Abstractions for Node.js](https://github.com/nodejs/nan)\nAPIs, the functions available in Node-API are used.\n\nAPIs exposed by Node-API are generally used to create and manipulate\nJavaScript values. Concepts and operations generally map to ideas specified\nin the ECMA-262 Language Specification. The APIs have the following\nproperties:\n\n* All Node-API calls return a status code of type `napi_status`. This\n  status indicates whether the API call succeeded or failed.\n* The API's return value is passed via an out parameter.\n* All JavaScript values are abstracted behind an opaque type named\n  `napi_value`.\n* In case of an error status code, additional information can be obtained\n  using `napi_get_last_error_info`. More information can be found in the error\n  handling section [Error handling](#error-handling).","summary":"Node-API (formerly N-API) is an API for building native Addons. It is independent from the underlying JavaScript runtime (for example, V8) and is maintained as part of Node.js itself. This API will be Application Binary Interface (ABI) stable across versions of Node.js. It is intended to insulate addons from changes in the underlying JavaScript engine and allow modules compiled for one major version to run on later major versions of Node.js without recompilation. The ABI Stability guide provides a more in-depth explanation.","examples":[],"children":[{"kind":"section","id":"writing-addons-in-various-programming-languages","name":"Writing addons in various programming languages","title":"Writing addons in various programming languages","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"Node-API is a C API that ensures ABI stability across Node.js versions\nand different compiler levels. With this stability guarantee, it is possible\nto write addons in other programming languages on top of Node-API. Refer\nto [language and engine bindings](https://github.com/nodejs/abi-stable-node/blob/doc/node-api-engine-bindings.md) for more programming languages and engines\nsupport details.\n\n[`node-addon-api`](https://github.com/nodejs/node-addon-api) is the official C++ binding that provides a more efficient way to\nwrite C++ code that calls Node-API. This wrapper is a header-only library that offers an inlinable C++ API.\nBinaries built with `node-addon-api` will depend on the symbols of the Node-API\nC-based functions exported by Node.js. The following code snippet is an example\nof `node-addon-api`:\n\n```cpp\nObject obj = Object::New(env);\nobj[\"foo\"] = String::New(env, \"bar\");\n```\n\nThe above `node-addon-api` C++ code is equivalent to the following C-based\nNode-API code:\n\n```cpp\nnapi_status status;\nnapi_value object, string;\nstatus = napi_create_object(env, &object);\nif (status != napi_ok) {\n  napi_throw_error(env, ...);\n  return;\n}\n\nstatus = napi_create_string_utf8(env, \"bar\", NAPI_AUTO_LENGTH, &string);\nif (status != napi_ok) {\n  napi_throw_error(env, ...);\n  return;\n}\n\nstatus = napi_set_named_property(env, object, \"foo\", string);\nif (status != napi_ok) {\n  napi_throw_error(env, ...);\n  return;\n}\n```\n\nThe end result is that the addon only uses the exported C APIs. Even though\nthe addon is written in C++, it still gets the benefits of the ABI stability\nprovided by the C Node-API.\n\nWhen using `node-addon-api` instead of the C APIs, start with the API [docs](https://github.com/nodejs/node-addon-api#api-documentation)\nfor `node-addon-api`.\n\nThe [Node-API Resource](https://nodejs.github.io/node-addon-examples/) offers\nan excellent orientation and tips for developers just getting started with\nNode-API and `node-addon-api`. Additional media resources can be found on the\n[Node-API Media](https://github.com/nodejs/abi-stable-node/blob/HEAD/node-api-media.md) page.","summary":"Node-API is a C API that ensures ABI stability across Node.js versions and different compiler levels. With this stability guarantee, it is possible to write addons in other programming languages on top of Node-API. Refer to language and engine bindings for more programming languages and engines support details.","examples":[{"language":"cpp","displayName":null,"code":"Object obj = Object::New(env);\nobj[\"foo\"] = String::New(env, \"bar\");"},{"language":"cpp","displayName":null,"code":"napi_status status;\nnapi_value object, string;\nstatus = napi_create_object(env, &object);\nif (status != napi_ok) {\n  napi_throw_error(env, ...);\n  return;\n}\n\nstatus = napi_create_string_utf8(env, \"bar\", NAPI_AUTO_LENGTH, &string);\nif (status != napi_ok) {\n  napi_throw_error(env, ...);\n  return;\n}\n\nstatus = napi_set_named_property(env, object, \"foo\", string);\nif (status != napi_ok) {\n  napi_throw_error(env, ...);\n  return;\n}"}],"children":[]},{"kind":"section","id":"implications-of-abi-stability","name":"Implications of ABI stability","title":"Implications of ABI stability","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"Although Node-API provides an ABI stability guarantee, other parts of Node.js do\nnot, and any external libraries used from the addon may not. In particular,\nnone of the following APIs provide an ABI stability guarantee across major\nversions:\n\n* the Node.js C++ APIs available via any of\n\n  ```cpp\n  #include <node.h>\n  #include <node_buffer.h>\n  #include <node_version.h>\n  #include <node_object_wrap.h>\n  ```\n\n* the libuv APIs which are also included with Node.js and available via\n\n  ```cpp\n  #include <uv.h>\n  ```\n\n* the V8 API available via\n\n  ```cpp\n  #include <v8.h>\n  ```\n\nThus, for an addon to remain ABI-compatible across Node.js major versions, it\nmust use Node-API exclusively by restricting itself to using\n\n```c\n#include <node_api.h>\n```\n\nand by checking, for all external libraries that it uses, that the external\nlibrary makes ABI stability guarantees similar to Node-API.","summary":"Although Node-API provides an ABI stability guarantee, other parts of Node.js do not, and any external libraries used from the addon may not. In particular, none of the following APIs provide an ABI stability guarantee across major versions:","examples":[{"language":"cpp","displayName":null,"code":"#include <node.h>\n#include <node_buffer.h>\n#include <node_version.h>\n#include <node_object_wrap.h>"},{"language":"cpp","displayName":null,"code":"#include <uv.h>"},{"language":"cpp","displayName":null,"code":"#include <v8.h>"},{"language":"c","displayName":null,"code":"#include <node_api.h>"}],"children":[{"kind":"section","id":"enum-values-in-abi-stability","name":"Enum values in ABI stability","title":"Enum values in ABI stability","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"All enum data types defined in Node-API should be considered as a fixed size\n`int32_t` value. Bit flag enum types should be explicitly documented, and they\nwork with bit operators like bit-OR (`|`) as a bit value. Unless otherwise\ndocumented, an enum type should be considered to be extensible.\n\nA new enum value will be added at the end of the enum definition. An enum value\nwill not be removed or renamed.\n\nFor an enum type returned from a Node-API function, or provided as an out\nparameter of a Node-API function, the value is an integer value and an addon\nshould handle unknown values. New values are allowed to be introduced without\na version guard. For example, when checking `napi_status` in switch statements,\nan addon should include a default branch, as new status codes may be introduced\nin newer Node.js versions.\n\nFor an enum type used in an in-parameter, the result of passing an unknown\ninteger value to Node-API functions is undefined unless otherwise documented.\nA new value is added with a version guard to indicate the Node-API version in\nwhich it was introduced. For example, `napi_get_all_property_names` can be\nextended with new enum value of `napi_key_filter`.\n\nFor an enum type used in both in-parameters and out-parameters, new values are\nallowed to be introduced without a version guard.","summary":"All enum data types defined in Node-API should be considered as a fixed size `int32_t` value. Bit flag enum types should be explicitly documented, and they work with bit operators like bit-OR (`|`) as a bit value. Unless otherwise documented, an enum type should be considered to be extensible.","examples":[],"children":[]}]},{"kind":"section","id":"building","name":"Building","title":"Building","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"Unlike modules written in JavaScript, developing and deploying Node.js\nnative addons using Node-API requires an additional set of tools. Besides the\nbasic tools required to develop for Node.js, the native addon developer\nrequires a toolchain that can compile C and C++ code into a binary. In\naddition, depending upon how the native addon is deployed, the *user* of\nthe native addon will also need to have a C/C++ toolchain installed.\n\nFor Linux developers, the necessary C/C++ toolchain packages are readily\navailable. [GCC](https://gcc.gnu.org) is widely used in the Node.js community to build and\ntest across a variety of platforms. For many developers, the [LLVM](https://llvm.org)\ncompiler infrastructure is also a good choice.\n\nFor Mac developers, [Xcode](https://developer.apple.com/xcode/) offers all the required compiler tools.\nHowever, it is not necessary to install the entire Xcode IDE. The following\ncommand installs the necessary toolchain:\n\n```bash\nxcode-select --install\n```\n\nFor Windows developers, [Visual Studio](https://visualstudio.microsoft.com) offers all the required compiler\ntools. However, it is not necessary to install the entire Visual Studio\nIDE. The following command installs the necessary toolchain:\n\n```bash\nnpm install --global windows-build-tools\n```\n\nThe sections below describe the additional tools available for developing\nand deploying Node.js native addons.","summary":"Unlike modules written in JavaScript, developing and deploying Node.js native addons using Node-API requires an additional set of tools. Besides the basic tools required to develop for Node.js, the native addon developer requires a toolchain that can compile C and C++ code into a binary. In addition, depending upon how the native addon is deployed, the _user_ of the native addon will also need to have a C/C++ toolchain installed.","examples":[{"language":"bash","displayName":null,"code":"xcode-select --install"},{"language":"bash","displayName":null,"code":"npm install --global windows-build-tools"}],"children":[{"kind":"section","id":"build-tools","name":"Build tools","title":"Build tools","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"Both the tools listed here require that *users* of the native\naddon have a C/C++ toolchain installed in order to successfully install\nthe native addon.","summary":"Both the tools listed here require that _users_ of the native addon have a C/C++ toolchain installed in order to successfully install the native addon.","examples":[],"children":[{"kind":"section","id":"node-gyp","name":"node-gyp","title":"node-gyp","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"[node-gyp](https://github.com/nodejs/node-gyp) is a build system based on the [gyp-next](https://github.com/nodejs/gyp-next) tool and comes bundled with npm.\nnode-gyp requires that Python be installed.\n\nHistorically, node-gyp has been the tool of choice for building native\naddons. It has widespread adoption and documentation. However, some\ndevelopers have run into limitations in node-gyp.","summary":"node-gyp is a build system based on the gyp-next tool and comes bundled with npm. node-gyp requires that Python be installed.","examples":[],"children":[]},{"kind":"section","id":"cmakejs","name":"CMake.js","title":"CMake.js","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"[CMake.js](https://github.com/cmake-js/cmake-js) is an alternative build system based on [CMake](https://cmake.org).\n\nCMake.js is a good choice for projects that already use CMake or for\ndevelopers affected by limitations in node-gyp. [`build_with_cmake`](https://github.com/nodejs/node-addon-examples/tree/main/src/8-tooling/build_with_cmake) is an\nexample of a CMake-based native addon project.","summary":"CMake.js is an alternative build system based on CMake.","examples":[],"children":[]}]},{"kind":"section","id":"uploading-precompiled-binaries","name":"Uploading precompiled binaries","title":"Uploading precompiled binaries","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"The three tools listed here permit native addon developers and maintainers\nto create and upload binaries to public or private servers. These tools are\ntypically integrated with CI/CD build systems like [Travis CI](https://travis-ci.org) and\n[AppVeyor](https://www.appveyor.com) to build and upload binaries for a variety of platforms and\narchitectures. These binaries are then available for download by users who\ndo not need to have a C/C++ toolchain installed.","summary":"The three tools listed here permit native addon developers and maintainers to create and upload binaries to public or private servers. These tools are typically integrated with CI/CD build systems like Travis CI and AppVeyor to build and upload binaries for a variety of platforms and architectures. These binaries are then available for download by users who do not need to have a C/C++ toolchain installed.","examples":[],"children":[{"kind":"section","id":"node-pre-gyp","name":"node-pre-gyp","title":"node-pre-gyp","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"[node-pre-gyp](https://github.com/mapbox/node-pre-gyp) is a tool based on node-gyp that adds the ability to\nupload binaries to a server of the developer's choice. node-pre-gyp has\nparticularly good support for uploading binaries to Amazon S3.","summary":"node-pre-gyp is a tool based on node-gyp that adds the ability to upload binaries to a server of the developer's choice. node-pre-gyp has particularly good support for uploading binaries to Amazon S3.","examples":[],"children":[]},{"kind":"section","id":"prebuild","name":"prebuild","title":"prebuild","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"[prebuild](https://github.com/prebuild/prebuild) is a tool that supports builds using either node-gyp or\nCMake.js. Unlike node-pre-gyp which supports a variety of servers, prebuild\nuploads binaries only to [GitHub releases](https://help.github.com/en/github/administering-a-repository/about-releases). prebuild is a good choice for\nGitHub projects using CMake.js.","summary":"prebuild is a tool that supports builds using either node-gyp or CMake.js. Unlike node-pre-gyp which supports a variety of servers, prebuild uploads binaries only to GitHub releases. prebuild is a good choice for GitHub projects using CMake.js.","examples":[],"children":[]},{"kind":"section","id":"prebuildify","name":"prebuildify","title":"prebuildify","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"[prebuildify](https://github.com/prebuild/prebuildify) is a tool based on node-gyp. The advantage of prebuildify is\nthat the built binaries are bundled with the native addon when it's\nuploaded to npm. The binaries are downloaded from npm and are immediately\navailable to the module user when the native addon is installed.","summary":"prebuildify is a tool based on node-gyp. The advantage of prebuildify is that the built binaries are bundled with the native addon when it's uploaded to npm. The binaries are downloaded from npm and are immediately available to the module user when the native addon is installed.","examples":[],"children":[]}]}]},{"kind":"section","id":"usage","name":"Usage","title":"Usage","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"In order to use the Node-API functions, include the file [`node_api.h`](https://github.com/nodejs/node/blob/HEAD/src/node_api.h) which\nis located in the src directory in the node development tree:\n\n```c\n#include <node_api.h>\n```\n\nThis will opt into the default `NAPI_VERSION` for the given release of Node.js.\nIn order to ensure compatibility with specific versions of Node-API, the version\ncan be specified explicitly when including the header:\n\n```c\n#define NAPI_VERSION 3\n#include <node_api.h>\n```\n\nThis restricts the Node-API surface to just the functionality that was available\nin the specified (and earlier) versions.\n\nSome of the Node-API surface is experimental and requires explicit opt-in:\n\n```c\n#define NAPI_EXPERIMENTAL\n#include <node_api.h>\n```\n\nIn this case the entire API surface, including any experimental APIs, will be\navailable to the module code.\n\nOccasionally, experimental features are introduced that affect already-released\nand stable APIs. These features can be disabled by an opt-out:\n\n```c\n#define NAPI_EXPERIMENTAL\n#define NODE_API_EXPERIMENTAL_<FEATURE_NAME>_OPT_OUT\n#include <node_api.h>\n```\n\nwhere `<FEATURE_NAME>` is the name of an experimental feature that affects both\nexperimental and stable APIs.","summary":"In order to use the Node-API functions, include the file `node_api.h` which is located in the src directory in the node development tree:","examples":[{"language":"c","displayName":null,"code":"#include <node_api.h>"},{"language":"c","displayName":null,"code":"#define NAPI_VERSION 3\n#include <node_api.h>"},{"language":"c","displayName":null,"code":"#define NAPI_EXPERIMENTAL\n#include <node_api.h>"},{"language":"c","displayName":null,"code":"#define NAPI_EXPERIMENTAL\n#define NODE_API_EXPERIMENTAL_<FEATURE_NAME>_OPT_OUT\n#include <node_api.h>"}],"children":[]},{"kind":"section","id":"node-api-version-matrix","name":"Node-API version matrix","title":"Node-API version matrix","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"Up until version 9, Node-API versions were additive and versioned\nindependently from Node.js. This meant that any version was\nan extension to the previous version in that it had all of\nthe APIs from the previous version with some additions. Each\nNode.js version only supported a single Node-API version.\nFor example v18.15.0 supports only Node-API version 8. ABI stability was\nachieved because 8 was a strict superset of all previous versions.\n\nAs of version 9, while Node-API versions continue to be versioned\nindependently, an add-on that ran with Node-API version 9 may need\ncode updates to run with Node-API version 10. ABI stability\nis maintained, however, because Node.js versions that support\nNode-API versions higher than 8 will support all versions\nbetween 8 and the highest version they support and will default\nto providing the version 8 APIs unless an add-on opts into a\nhigher Node-API version. This approach provides the flexibility\nof better optimizing existing Node-API functions while\nmaintaining ABI stability. Existing add-ons can continue to run without\nrecompilation using an earlier version of Node-API. If an add-on\nneeds functionality from a newer Node-API version, changes to existing\ncode and recompilation will be needed to use those new functions anyway.\n\nIn versions of Node.js that support Node-API version 9 and later, defining\n`NAPI_VERSION=X` and using the existing add-on initialization macros\nwill bake in the requested Node-API version that will be used at runtime\ninto the add-on. If `NAPI_VERSION` is not set it will default to 8.\n\nThis table may not be up to date in older streams, the most up to date\ninformation is in the latest API documentation in:\n[Node-API version matrix](https://nodejs.org/docs/latest/api/n-api.html#node-api-version-matrix)\n\n<!-- For accessibility purposes, this table needs row headers. That means we\n     can't do it in markdown. Hence, the raw HTML. -->\n\n<table>\n  <tr>\n    <th>Node-API version</th>\n    <th scope=\"col\">Supported In</th>\n  </tr>\n  <tr>\n    <th scope=\"row\">10</th>\n    <td>v22.14.0+, 23.6.0+ and all later versions</td>\n  </tr>\n  <tr>\n    <th scope=\"row\">9</th>\n    <td>v18.17.0+, 20.3.0+, 21.0.0 and all later versions</td>\n  </tr>\n  <tr>\n    <th scope=\"row\">8</th>\n    <td>v12.22.0+, v14.17.0+, v15.12.0+, 16.0.0 and all later versions</td>\n  </tr>\n  <tr>\n    <th scope=\"row\">7</th>\n    <td>v10.23.0+, v12.19.0+, v14.12.0+, 15.0.0 and all later versions</td>\n  </tr>\n  <tr>\n    <th scope=\"row\">6</th>\n    <td>v10.20.0+, v12.17.0+, 14.0.0 and all later versions</td>\n  </tr>\n  <tr>\n    <th scope=\"row\">5</th>\n    <td>v10.17.0+, v12.11.0+, 13.0.0 and all later versions</td>\n  </tr>\n  <tr>\n    <th scope=\"row\">4</th>\n    <td>v10.16.0+, v11.8.0+, 12.0.0 and all later versions</td>\n  </tr>\n  </tr>\n    <tr>\n    <th scope=\"row\">3</th>\n    <td>v6.14.2*, 8.11.2+, v9.11.0+*, 10.0.0 and all later versions</td>\n  </tr>\n  <tr>\n    <th scope=\"row\">2</th>\n    <td>v8.10.0+*, v9.3.0+*, 10.0.0 and all later versions</td>\n  </tr>\n  <tr>\n    <th scope=\"row\">1</th>\n    <td>v8.6.0+**, v9.0.0+*, 10.0.0 and all later versions</td>\n  </tr>\n</table>\n\n\\* Node-API was experimental.\n\n\\*\\* Node.js 8.0.0 included Node-API as experimental. It was released as\nNode-API version 1 but continued to evolve until Node.js 8.6.0. The API is\ndifferent in versions prior to Node.js 8.6.0. We recommend Node-API version 3 or\nlater.\n\nEach API documented for Node-API will have a header named `added in:`, and APIs\nwhich are stable will have the additional header `Node-API version:`.\nAPIs are directly usable when using a Node.js version which supports\nthe Node-API version shown in `Node-API version:` or higher.\nWhen using a Node.js version that does not support the\n`Node-API version:` listed or if there is no `Node-API version:` listed,\nthen the API will only be available if\n`#define NAPI_EXPERIMENTAL` precedes the inclusion of `node_api.h`\nor `js_native_api.h`. If an API appears not to be available on\na version of Node.js which is later than the one shown in `added in:` then\nthis is most likely the reason for the apparent absence.\n\nThe Node-APIs associated strictly with accessing ECMAScript features from native\ncode can be found separately in `js_native_api.h` and `js_native_api_types.h`.\nThe APIs defined in these headers are included in `node_api.h` and\n`node_api_types.h`. The headers are structured in this way in order to allow\nimplementations of Node-API outside of Node.js. For those implementations the\nNode.js specific APIs may not be applicable.\n\nThe Node.js-specific parts of an addon can be separated from the code that\nexposes the actual functionality to the JavaScript environment so that the\nlatter may be used with multiple implementations of Node-API. In the example\nbelow, `addon.c` and `addon.h` refer only to `js_native_api.h`. This ensures\nthat `addon.c` can be reused to compile against either the Node.js\nimplementation of Node-API or any implementation of Node-API outside of Node.js.\n\n`addon_node.c` is a separate file that contains the Node.js specific entry point\nto the addon and which instantiates the addon by calling into `addon.c` when the\naddon is loaded into a Node.js environment.\n\n```c\n// addon.h\n#ifndef _ADDON_H_\n#define _ADDON_H_\n#include <js_native_api.h>\nnapi_value create_addon(napi_env env);\n#endif  // _ADDON_H_\n```\n\n```c\n// addon.c\n#include \"addon.h\"\n\n#define NODE_API_CALL(env, call)                                  \\\n  do {                                                            \\\n    napi_status status = (call);                                  \\\n    if (status != napi_ok) {                                      \\\n      const napi_extended_error_info* error_info = NULL;          \\\n      napi_get_last_error_info((env), &error_info);               \\\n      const char* err_message = error_info->error_message;        \\\n      bool is_pending;                                            \\\n      napi_is_exception_pending((env), &is_pending);              \\\n      /* If an exception is already pending, don't rethrow it */  \\\n      if (!is_pending) {                                          \\\n        const char* message = (err_message == NULL)               \\\n            ? \"empty error message\"                               \\\n            : err_message;                                        \\\n        napi_throw_error((env), NULL, message);                   \\\n      }                                                           \\\n      return NULL;                                                \\\n    }                                                             \\\n  } while(0)\n\nstatic napi_value\nDoSomethingUseful(napi_env env, napi_callback_info info) {\n  // Do something useful.\n  return NULL;\n}\n\nnapi_value create_addon(napi_env env) {\n  napi_value result;\n  NODE_API_CALL(env, napi_create_object(env, &result));\n\n  napi_value exported_function;\n  NODE_API_CALL(env, napi_create_function(env,\n                                          \"doSomethingUseful\",\n                                          NAPI_AUTO_LENGTH,\n                                          DoSomethingUseful,\n                                          NULL,\n                                          &exported_function));\n\n  NODE_API_CALL(env, napi_set_named_property(env,\n                                             result,\n                                             \"doSomethingUseful\",\n                                             exported_function));\n\n  return result;\n}\n```\n\n```c\n// addon_node.c\n#include <node_api.h>\n#include \"addon.h\"\n\nNAPI_MODULE_INIT(/* napi_env env, napi_value exports */) {\n  // This function body is expected to return a `napi_value`.\n  // The variables `napi_env env` and `napi_value exports` may be used within\n  // the body, as they are provided by the definition of `NAPI_MODULE_INIT()`.\n  return create_addon(env);\n}\n```","summary":"Up until version 9, Node-API versions were additive and versioned independently from Node.js. This meant that any version was an extension to the previous version in that it had all of the APIs from the previous version with some additions. Each Node.js version only supported a single Node-API version. For example v18.15.0 supports only Node-API version 8. ABI stability was achieved because 8 was a strict superset of all previous versions.","examples":[{"language":"c","displayName":null,"code":"// addon.h\n#ifndef _ADDON_H_\n#define _ADDON_H_\n#include <js_native_api.h>\nnapi_value create_addon(napi_env env);\n#endif  // _ADDON_H_"},{"language":"c","displayName":null,"code":"// addon.c\n#include \"addon.h\"\n\n#define NODE_API_CALL(env, call)                                  \\\n  do {                                                            \\\n    napi_status status = (call);                                  \\\n    if (status != napi_ok) {                                      \\\n      const napi_extended_error_info* error_info = NULL;          \\\n      napi_get_last_error_info((env), &error_info);               \\\n      const char* err_message = error_info->error_message;        \\\n      bool is_pending;                                            \\\n      napi_is_exception_pending((env), &is_pending);              \\\n      /* If an exception is already pending, don't rethrow it */  \\\n      if (!is_pending) {                                          \\\n        const char* message = (err_message == NULL)               \\\n            ? \"empty error message\"                               \\\n            : err_message;                                        \\\n        napi_throw_error((env), NULL, message);                   \\\n      }                                                           \\\n      return NULL;                                                \\\n    }                                                             \\\n  } while(0)\n\nstatic napi_value\nDoSomethingUseful(napi_env env, napi_callback_info info) {\n  // Do something useful.\n  return NULL;\n}\n\nnapi_value create_addon(napi_env env) {\n  napi_value result;\n  NODE_API_CALL(env, napi_create_object(env, &result));\n\n  napi_value exported_function;\n  NODE_API_CALL(env, napi_create_function(env,\n                                          \"doSomethingUseful\",\n                                          NAPI_AUTO_LENGTH,\n                                          DoSomethingUseful,\n                                          NULL,\n                                          &exported_function));\n\n  NODE_API_CALL(env, napi_set_named_property(env,\n                                             result,\n                                             \"doSomethingUseful\",\n                                             exported_function));\n\n  return result;\n}"},{"language":"c","displayName":null,"code":"// addon_node.c\n#include <node_api.h>\n#include \"addon.h\"\n\nNAPI_MODULE_INIT(/* napi_env env, napi_value exports */) {\n  // This function body is expected to return a `napi_value`.\n  // The variables `napi_env env` and `napi_value exports` may be used within\n  // the body, as they are provided by the definition of `NAPI_MODULE_INIT()`.\n  return create_addon(env);\n}"}],"children":[]},{"kind":"section","id":"environment-life-cycle-apis","name":"Environment life cycle APIs","title":"Environment life cycle APIs","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"[Section Agents](https://tc39.es/ecma262/#sec-agents) of the [ECMAScript Language Specification](https://tc39.es/ecma262/) defines the concept\nof an \"Agent\" as a self-contained environment in which JavaScript code runs.\nMultiple such Agents may be started and terminated either concurrently or in\nsequence by the process.\n\nA Node.js environment corresponds to an ECMAScript Agent. In the main process,\nan environment is created at startup, and additional environments can be created\non separate threads to serve as [worker threads](https://nodejs.org/api/worker_threads.html). When Node.js is embedded in\nanother application, the main thread of the application may also construct and\ndestroy a Node.js environment multiple times during the life cycle of the\napplication process such that each Node.js environment created by the\napplication may, in turn, during its life cycle create and destroy additional\nenvironments as worker threads.\n\nFrom the perspective of a native addon this means that the bindings it provides\nmay be called multiple times, from multiple contexts, and even concurrently from\nmultiple threads.\n\nNative addons may need to allocate global state which they use during\ntheir life cycle of an Node.js environment such that the state can be\nunique to each instance of the addon.\n\nTo this end, Node-API provides a way to associate data such that its life cycle\nis tied to the life cycle of a Node.js environment.","summary":"Section Agents of the ECMAScript Language Specification defines the concept of an \"Agent\" as a self-contained environment in which JavaScript code runs. Multiple such Agents may be started and terminated either concurrently or in sequence by the process.","examples":[],"children":[{"kind":"section","id":"napi_set_instance_data","name":"napi_set_instance_data","title":"`napi_set_instance_data`","scope":"module","overloadOf":null,"stability":null,"added":["v12.8.0","v10.20.0"],"deprecated":[],"removed":[],"napiVersion":[6],"changes":[],"description":"```c\nnapi_status napi_set_instance_data(node_api_basic_env env,\n                                   void* data,\n                                   napi_finalize finalize_cb,\n                                   void* finalize_hint);\n```\n\n* `[in] env`: The environment that the Node-API call is invoked under.\n* `[in] data`: The data item to make available to bindings of this instance.\n* `[in] finalize_cb`: The function to call when the environment is being torn\n  down. The function receives `data` so that it might free it.\n  [`napi_finalize`](#napi_finalize) provides more details.\n* `[in] finalize_hint`: Optional hint to pass to the finalize callback during\n  collection.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API associates `data` with the currently running Node.js environment. `data`\ncan later be retrieved using `napi_get_instance_data()`. Any existing data\nassociated with the currently running Node.js environment which was set by means\nof a previous call to `napi_set_instance_data()` will be overwritten. If a\n`finalize_cb` was provided by the previous call, it will not be called.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_set_instance_data(node_api_basic_env env,\n                                   void* data,\n                                   napi_finalize finalize_cb,\n                                   void* finalize_hint);"}],"children":[]},{"kind":"section","id":"napi_get_instance_data","name":"napi_get_instance_data","title":"`napi_get_instance_data`","scope":"module","overloadOf":null,"stability":null,"added":["v12.8.0","v10.20.0"],"deprecated":[],"removed":[],"napiVersion":[6],"changes":[],"description":"```c\nnapi_status napi_get_instance_data(node_api_basic_env env,\n                                   void** data);\n```\n\n* `[in] env`: The environment that the Node-API call is invoked under.\n* `[out] data`: The data item that was previously associated with the currently\n  running Node.js environment by a call to `napi_set_instance_data()`.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API retrieves data that was previously associated with the currently\nrunning Node.js environment via `napi_set_instance_data()`. If no data is set,\nthe call will succeed and `data` will be set to `NULL`.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_get_instance_data(node_api_basic_env env,\n                                   void** data);"}],"children":[]}]},{"kind":"section","id":"basic-node-api-data-types","name":"Basic Node-API data types","title":"Basic Node-API data types","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"Node-API exposes the following fundamental data types as abstractions that are\nconsumed by the various APIs. These APIs should be treated as opaque,\nintrospectable only with other Node-API calls.","summary":"Node-API exposes the following fundamental data types as abstractions that are consumed by the various APIs. These APIs should be treated as opaque, introspectable only with other Node-API calls.","examples":[],"children":[{"kind":"section","id":"napi_status","name":"napi_status","title":"`napi_status`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"Integral status code indicating the success or failure of a Node-API call.\nCurrently, the following status codes are supported.\n\n```c\ntypedef enum {\n  napi_ok,\n  napi_invalid_arg,\n  napi_object_expected,\n  napi_string_expected,\n  napi_name_expected,\n  napi_function_expected,\n  napi_number_expected,\n  napi_boolean_expected,\n  napi_array_expected,\n  napi_generic_failure,\n  napi_pending_exception,\n  napi_cancelled,\n  napi_escape_called_twice,\n  napi_handle_scope_mismatch,\n  napi_callback_scope_mismatch,\n  napi_queue_full,\n  napi_closing,\n  napi_bigint_expected,\n  napi_date_expected,\n  napi_arraybuffer_expected,\n  napi_detachable_arraybuffer_expected,\n  napi_would_deadlock,  /* unused */\n  napi_no_external_buffers_allowed,\n  napi_cannot_run_js\n} napi_status;\n```\n\nIf additional information is required upon an API returning a failed status,\nit can be obtained by calling `napi_get_last_error_info`.","summary":"Integral status code indicating the success or failure of a Node-API call. Currently, the following status codes are supported.","examples":[{"language":"c","displayName":null,"code":"typedef enum {\n  napi_ok,\n  napi_invalid_arg,\n  napi_object_expected,\n  napi_string_expected,\n  napi_name_expected,\n  napi_function_expected,\n  napi_number_expected,\n  napi_boolean_expected,\n  napi_array_expected,\n  napi_generic_failure,\n  napi_pending_exception,\n  napi_cancelled,\n  napi_escape_called_twice,\n  napi_handle_scope_mismatch,\n  napi_callback_scope_mismatch,\n  napi_queue_full,\n  napi_closing,\n  napi_bigint_expected,\n  napi_date_expected,\n  napi_arraybuffer_expected,\n  napi_detachable_arraybuffer_expected,\n  napi_would_deadlock,  /* unused */\n  napi_no_external_buffers_allowed,\n  napi_cannot_run_js\n} napi_status;"}],"children":[]},{"kind":"section","id":"napi_extended_error_info","name":"napi_extended_error_info","title":"`napi_extended_error_info`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\ntypedef struct {\n  const char* error_message;\n  void* engine_reserved;\n  uint32_t engine_error_code;\n  napi_status error_code;\n} napi_extended_error_info;\n```\n\n* `error_message`: UTF8-encoded string containing a VM-neutral description of\n  the error.\n* `engine_reserved`: Reserved for VM-specific error details. This is currently\n  not implemented for any VM.\n* `engine_error_code`: VM-specific error code. This is currently\n  not implemented for any VM.\n* `error_code`: The Node-API status code that originated with the last error.\n\nSee the [Error handling](#error-handling) section for additional information.","summary":"See the Error handling section for additional information.","examples":[{"language":"c","displayName":null,"code":"typedef struct {\n  const char* error_message;\n  void* engine_reserved;\n  uint32_t engine_error_code;\n  napi_status error_code;\n} napi_extended_error_info;"}],"children":[]},{"kind":"section","id":"napi_env","name":"napi_env","title":"`napi_env`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"`napi_env` is used to represent a context that the underlying Node-API\nimplementation can use to persist VM-specific state. This structure is passed\nto native functions when they're invoked, and it must be passed back when\nmaking Node-API calls. Specifically, the same `napi_env` that was passed in when\nthe initial native function was called must be passed to any subsequent\nnested Node-API calls. Caching the `napi_env` for the purpose of general reuse,\nand passing the `napi_env` between instances of the same addon running on\ndifferent [`Worker`](worker_threads.html#class-worker) threads is not allowed. The `napi_env` becomes invalid\nwhen an instance of a native addon is unloaded. Notification of this event is\ndelivered through the callbacks given to [`napi_add_env_cleanup_hook`](#napi_add_env_cleanup_hook) and\n[`napi_set_instance_data`](#napi_set_instance_data).","summary":"`napi_env` is used to represent a context that the underlying Node-API implementation can use to persist VM-specific state. This structure is passed to native functions when they're invoked, and it must be passed back when making Node-API calls. Specifically, the same `napi_env` that was passed in when the initial native function was called must be passed to any subsequent nested Node-API calls. Caching the `napi_env` for the purpose of general reuse, and passing the `napi_env` between instances of the same addon running on different `Worker` threads is not allowed. The `napi_env` becomes invalid when an instance of a native addon is unloaded. Notification of this event is delivered through the callbacks given to `napi_add_env_cleanup_hook` and `napi_set_instance_data`.","examples":[],"children":[]},{"kind":"section","id":"node_api_basic_env","name":"node_api_basic_env","title":"`node_api_basic_env`","scope":"module","overloadOf":null,"stability":{"index":"1","description":"Experimental"},"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"This variant of `napi_env` is passed to synchronous finalizers\n([`node_api_basic_finalize`](#node_api_basic_finalize)). There is a subset of Node-APIs which accept\na parameter of type `node_api_basic_env` as their first argument. These APIs do\nnot access the state of the JavaScript engine and are thus safe to call from\nsynchronous finalizers. Passing a parameter of type `napi_env` to these APIs is\nallowed, however, passing a parameter of type `node_api_basic_env` to APIs that\naccess the JavaScript engine state is not allowed. Attempting to do so without\na cast will produce a compiler warning or an error when add-ons are compiled\nwith flags which cause them to emit warnings and/or errors when incorrect\npointer types are passed into a function. Calling such APIs from a synchronous\nfinalizer will ultimately result in the termination of the application.","summary":"This variant of `napi_env` is passed to synchronous finalizers (`node_api_basic_finalize`). There is a subset of Node-APIs which accept a parameter of type `node_api_basic_env` as their first argument. These APIs do not access the state of the JavaScript engine and are thus safe to call from synchronous finalizers. Passing a parameter of type `napi_env` to these APIs is allowed, however, passing a parameter of type `node_api_basic_env` to APIs that access the JavaScript engine state is not allowed. Attempting to do so without a cast will produce a compiler warning or an error when add-ons are compiled with flags which cause them to emit warnings and/or errors when incorrect pointer types are passed into a function. Calling such APIs from a synchronous finalizer will ultimately result in the termination of the application.","examples":[],"children":[]},{"kind":"section","id":"napi_value","name":"napi_value","title":"`napi_value`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"This is an opaque pointer that is used to represent a JavaScript value.","summary":"This is an opaque pointer that is used to represent a JavaScript value.","examples":[],"children":[]},{"kind":"section","id":"napi_threadsafe_function","name":"napi_threadsafe_function","title":"`napi_threadsafe_function`","scope":"module","overloadOf":null,"stability":null,"added":["v10.6.0"],"deprecated":[],"removed":[],"napiVersion":[4],"changes":[],"description":"This is an opaque pointer that represents a JavaScript function which can be\ncalled asynchronously from multiple threads via\n`napi_call_threadsafe_function()`.","summary":"This is an opaque pointer that represents a JavaScript function which can be called asynchronously from multiple threads via `napi_call_threadsafe_function()`.","examples":[],"children":[]},{"kind":"section","id":"napi_threadsafe_function_release_mode","name":"napi_threadsafe_function_release_mode","title":"`napi_threadsafe_function_release_mode`","scope":"module","overloadOf":null,"stability":null,"added":["v10.6.0"],"deprecated":[],"removed":[],"napiVersion":[4],"changes":[],"description":"A value to be given to `napi_release_threadsafe_function()` to indicate whether\nthe thread-safe function is to be closed immediately (`napi_tsfn_abort`) or\nmerely released (`napi_tsfn_release`) and thus available for subsequent use via\n`napi_acquire_threadsafe_function()` and `napi_call_threadsafe_function()`.\n\n```c\ntypedef enum {\n  napi_tsfn_release,\n  napi_tsfn_abort\n} napi_threadsafe_function_release_mode;\n```","summary":"A value to be given to `napi_release_threadsafe_function()` to indicate whether the thread-safe function is to be closed immediately (`napi_tsfn_abort`) or merely released (`napi_tsfn_release`) and thus available for subsequent use via `napi_acquire_threadsafe_function()` and `napi_call_threadsafe_function()`.","examples":[{"language":"c","displayName":null,"code":"typedef enum {\n  napi_tsfn_release,\n  napi_tsfn_abort\n} napi_threadsafe_function_release_mode;"}],"children":[]},{"kind":"section","id":"napi_threadsafe_function_call_mode","name":"napi_threadsafe_function_call_mode","title":"`napi_threadsafe_function_call_mode`","scope":"module","overloadOf":null,"stability":null,"added":["v10.6.0"],"deprecated":[],"removed":[],"napiVersion":[4],"changes":[],"description":"A value to be given to `napi_call_threadsafe_function()` to indicate whether\nthe call should block whenever the queue associated with the thread-safe\nfunction is full.\n\n```c\ntypedef enum {\n  napi_tsfn_nonblocking,\n  napi_tsfn_blocking\n} napi_threadsafe_function_call_mode;\n```","summary":"A value to be given to `napi_call_threadsafe_function()` to indicate whether the call should block whenever the queue associated with the thread-safe function is full.","examples":[{"language":"c","displayName":null,"code":"typedef enum {\n  napi_tsfn_nonblocking,\n  napi_tsfn_blocking\n} napi_threadsafe_function_call_mode;"}],"children":[]},{"kind":"section","id":"node-api-memory-management-types","name":"Node-API memory management types","title":"Node-API memory management types","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"","summary":"","examples":[],"children":[{"kind":"section","id":"napi_handle_scope","name":"napi_handle_scope","title":"`napi_handle_scope`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"This is an abstraction used to control and modify the lifetime of objects\ncreated within a particular scope. In general, Node-API values are created\nwithin the context of a handle scope. When a native method is called from\nJavaScript, a default handle scope will exist. If the user does not explicitly\ncreate a new handle scope, Node-API values will be created in the default handle\nscope. For any invocations of code outside the execution of a native method\n(for instance, during a libuv callback invocation), the module is required to\ncreate a scope before invoking any functions that can result in the creation\nof JavaScript values.\n\nHandle scopes are created using [`napi_open_handle_scope`](#napi_open_handle_scope) and are destroyed\nusing [`napi_close_handle_scope`](#napi_close_handle_scope). Closing the scope can indicate to the GC\nthat all `napi_value`s created during the lifetime of the handle scope are no\nlonger referenced from the current stack frame.\n\nFor more details, review the [Object lifetime management](#object-lifetime-management).","summary":"This is an abstraction used to control and modify the lifetime of objects created within a particular scope. In general, Node-API values are created within the context of a handle scope. When a native method is called from JavaScript, a default handle scope will exist. If the user does not explicitly create a new handle scope, Node-API values will be created in the default handle scope. For any invocations of code outside the execution of a native method (for instance, during a libuv callback invocation), the module is required to create a scope before invoking any functions that can result in the creation of JavaScript values.","examples":[],"children":[]},{"kind":"section","id":"napi_escapable_handle_scope","name":"napi_escapable_handle_scope","title":"`napi_escapable_handle_scope`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"Escapable handle scopes are a special type of handle scope to return values\ncreated within a particular handle scope to a parent scope.","summary":"Escapable handle scopes are a special type of handle scope to return values created within a particular handle scope to a parent scope.","examples":[],"children":[]},{"kind":"section","id":"napi_ref","name":"napi_ref","title":"`napi_ref`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"This is the abstraction to use to reference a `napi_value`. This allows for\nusers to manage the lifetimes of JavaScript values, including defining their\nminimum lifetimes explicitly.\n\nFor more details, review the [Object lifetime management](#object-lifetime-management).","summary":"This is the abstraction to use to reference a `napi_value`. This allows for users to manage the lifetimes of JavaScript values, including defining their minimum lifetimes explicitly.","examples":[],"children":[]},{"kind":"section","id":"napi_type_tag","name":"napi_type_tag","title":"`napi_type_tag`","scope":"module","overloadOf":null,"stability":null,"added":["v14.8.0","v12.19.0"],"deprecated":[],"removed":[],"napiVersion":[8],"changes":[],"description":"A 128-bit value stored as two unsigned 64-bit integers. It serves as a UUID\nwith which JavaScript objects or [externals](#napi_create_external) can be \"tagged\" in order to\nensure that they are of a certain type. This is a stronger check than\n[`napi_instanceof`](#napi_instanceof), because the latter can report a false positive if the\nobject's prototype has been manipulated. Type-tagging is most useful in\nconjunction with [`napi_wrap`](#napi_wrap) because it ensures that the pointer retrieved\nfrom a wrapped object can be safely cast to the native type corresponding to the\ntype tag that had been previously applied to the JavaScript object.\n\n```c\ntypedef struct {\n  uint64_t lower;\n  uint64_t upper;\n} napi_type_tag;\n```","summary":"A 128-bit value stored as two unsigned 64-bit integers. It serves as a UUID with which JavaScript objects or externals can be \"tagged\" in order to ensure that they are of a certain type. This is a stronger check than `napi_instanceof`, because the latter can report a false positive if the object's prototype has been manipulated. Type-tagging is most useful in conjunction with `napi_wrap` because it ensures that the pointer retrieved from a wrapped object can be safely cast to the native type corresponding to the type tag that had been previously applied to the JavaScript object.","examples":[{"language":"c","displayName":null,"code":"typedef struct {\n  uint64_t lower;\n  uint64_t upper;\n} napi_type_tag;"}],"children":[]},{"kind":"section","id":"napi_async_cleanup_hook_handle","name":"napi_async_cleanup_hook_handle","title":"`napi_async_cleanup_hook_handle`","scope":"module","overloadOf":null,"stability":null,"added":["v14.10.0","v12.19.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"An opaque value returned by [`napi_add_async_cleanup_hook`](#napi_add_async_cleanup_hook). It must be passed\nto [`napi_remove_async_cleanup_hook`](#napi_remove_async_cleanup_hook) when the chain of asynchronous cleanup\nevents completes.","summary":"An opaque value returned by `napi_add_async_cleanup_hook`. It must be passed to `napi_remove_async_cleanup_hook` when the chain of asynchronous cleanup events completes.","examples":[],"children":[]}]},{"kind":"section","id":"node-api-callback-types","name":"Node-API callback types","title":"Node-API callback types","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"","summary":"","examples":[],"children":[{"kind":"section","id":"napi_callback_info","name":"napi_callback_info","title":"`napi_callback_info`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"Opaque datatype that is passed to a callback function. It can be used for\ngetting additional information about the context in which the callback was\ninvoked.","summary":"Opaque datatype that is passed to a callback function. It can be used for getting additional information about the context in which the callback was invoked.","examples":[],"children":[]},{"kind":"section","id":"napi_callback","name":"napi_callback","title":"`napi_callback`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"Function pointer type for user-provided native functions which are to be\nexposed to JavaScript via Node-API. Callback functions should satisfy the\nfollowing signature:\n\n```c\ntypedef napi_value (*napi_callback)(napi_env, napi_callback_info);\n```\n\nUnless for reasons discussed in [Object Lifetime Management](#object-lifetime-management), creating a\nhandle and/or callback scope inside a `napi_callback` is not necessary.","summary":"Function pointer type for user-provided native functions which are to be exposed to JavaScript via Node-API. Callback functions should satisfy the following signature:","examples":[{"language":"c","displayName":null,"code":"typedef napi_value (*napi_callback)(napi_env, napi_callback_info);"}],"children":[]},{"kind":"section","id":"node_api_basic_finalize","name":"node_api_basic_finalize","title":"`node_api_basic_finalize`","scope":"module","overloadOf":null,"stability":{"index":"1","description":"Experimental"},"added":["v21.6.0","v20.12.0","v18.20.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"Function pointer type for add-on provided functions that allow the user to be\nnotified when externally-owned data is ready to be cleaned up because the\nobject it was associated with has been garbage-collected. The user must provide\na function satisfying the following signature which would get called upon the\nobject's collection. Currently, `node_api_basic_finalize` can be used for\nfinding out when objects that have external data are collected.\n\n```c\ntypedef void (*node_api_basic_finalize)(node_api_basic_env env,\n                                      void* finalize_data,\n                                      void* finalize_hint);\n```\n\nUnless for reasons discussed in [Object Lifetime Management](#object-lifetime-management), creating a\nhandle and/or callback scope inside the function body is not necessary.\n\nSince these functions may be called while the JavaScript engine is in a state\nwhere it cannot execute JavaScript code, only Node-APIs which accept a\n`node_api_basic_env` as their first parameter may be called.\n[`node_api_post_finalizer`](#node_api_post_finalizer) can be used to schedule Node-API calls that\nrequire access to the JavaScript engine's state to run after the current\ngarbage collection cycle has completed.\n\nIn the case of [`node_api_create_external_string_latin1`](#node_api_create_external_string_latin1) and\n[`node_api_create_external_string_utf16`](#node_api_create_external_string_utf16) the `env` parameter may be null,\nbecause external strings can be collected during the latter part of environment\nshutdown.\n\nChange History:\n\n* experimental (`NAPI_EXPERIMENTAL`):\n\n  Only Node-API calls that accept a `node_api_basic_env` as their first\n  parameter may be called, otherwise the application will be terminated with an\n  appropriate error message. This feature can be turned off by defining\n  `NODE_API_EXPERIMENTAL_BASIC_ENV_OPT_OUT`.","summary":"Function pointer type for add-on provided functions that allow the user to be notified when externally-owned data is ready to be cleaned up because the object it was associated with has been garbage-collected. The user must provide a function satisfying the following signature which would get called upon the object's collection. Currently, `node_api_basic_finalize` can be used for finding out when objects that have external data are collected.","examples":[{"language":"c","displayName":null,"code":"typedef void (*node_api_basic_finalize)(node_api_basic_env env,\n                                      void* finalize_data,\n                                      void* finalize_hint);"}],"children":[]},{"kind":"section","id":"napi_finalize","name":"napi_finalize","title":"`napi_finalize`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"Function pointer type for add-on provided function that allow the user to\nschedule a group of calls to Node-APIs in response to a garbage collection\nevent, after the garbage collection cycle has completed. These function\npointers can be used with [`node_api_post_finalizer`](#node_api_post_finalizer).\n\n```c\ntypedef void (*napi_finalize)(napi_env env,\n                              void* finalize_data,\n                              void* finalize_hint);\n```\n\nChange History:\n\n* experimental (`NAPI_EXPERIMENTAL` is defined):\n\n  A function of this type may no longer be used as a finalizer, except with\n  [`node_api_post_finalizer`](#node_api_post_finalizer). [`node_api_basic_finalize`](#node_api_basic_finalize) must be used\n  instead. This feature can be turned off by defining\n  `NODE_API_EXPERIMENTAL_BASIC_ENV_OPT_OUT`.","summary":"Function pointer type for add-on provided function that allow the user to schedule a group of calls to Node-APIs in response to a garbage collection event, after the garbage collection cycle has completed. These function pointers can be used with `node_api_post_finalizer`.","examples":[{"language":"c","displayName":null,"code":"typedef void (*napi_finalize)(napi_env env,\n                              void* finalize_data,\n                              void* finalize_hint);"}],"children":[]},{"kind":"section","id":"napi_async_execute_callback","name":"napi_async_execute_callback","title":"`napi_async_execute_callback`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"Function pointer used with functions that support asynchronous\noperations. Callback functions must satisfy the following signature:\n\n```c\ntypedef void (*napi_async_execute_callback)(napi_env env, void* data);\n```\n\nImplementations of this function must avoid making Node-API calls that execute\nJavaScript or interact with JavaScript objects. Node-API calls should be in the\n`napi_async_complete_callback` instead. Do not use the `napi_env` parameter as\nit will likely result in execution of JavaScript.","summary":"Function pointer used with functions that support asynchronous operations. Callback functions must satisfy the following signature:","examples":[{"language":"c","displayName":null,"code":"typedef void (*napi_async_execute_callback)(napi_env env, void* data);"}],"children":[]},{"kind":"section","id":"napi_async_complete_callback","name":"napi_async_complete_callback","title":"`napi_async_complete_callback`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"Function pointer used with functions that support asynchronous\noperations. Callback functions must satisfy the following signature:\n\n```c\ntypedef void (*napi_async_complete_callback)(napi_env env,\n                                             napi_status status,\n                                             void* data);\n```\n\nUnless for reasons discussed in [Object Lifetime Management](#object-lifetime-management), creating a\nhandle and/or callback scope inside the function body is not necessary.","summary":"Function pointer used with functions that support asynchronous operations. Callback functions must satisfy the following signature:","examples":[{"language":"c","displayName":null,"code":"typedef void (*napi_async_complete_callback)(napi_env env,\n                                             napi_status status,\n                                             void* data);"}],"children":[]},{"kind":"section","id":"napi_threadsafe_function_call_js","name":"napi_threadsafe_function_call_js","title":"`napi_threadsafe_function_call_js`","scope":"module","overloadOf":null,"stability":null,"added":["v10.6.0"],"deprecated":[],"removed":[],"napiVersion":[4],"changes":[],"description":"Function pointer used with asynchronous thread-safe function calls. The callback\nwill be called on the main thread. Its purpose is to use a data item arriving\nvia the queue from one of the secondary threads to construct the parameters\nnecessary for a call into JavaScript, usually via `napi_call_function`, and then\nmake the call into JavaScript.\n\nThe data arriving from the secondary thread via the queue is given in the `data`\nparameter and the JavaScript function to call is given in the `js_callback`\nparameter.\n\nNode-API sets up the environment prior to calling this callback, so it is\nsufficient to call the JavaScript function via `napi_call_function` rather than\nvia `napi_make_callback`.\n\nCallback functions must satisfy the following signature:\n\n```c\ntypedef void (*napi_threadsafe_function_call_js)(napi_env env,\n                                                 napi_value js_callback,\n                                                 void* context,\n                                                 void* data);\n```\n\n* `[in] env`: The environment to use for API calls, or `NULL` if the thread-safe\n  function is being torn down and `data` may need to be freed.\n* `[in] js_callback`: The JavaScript function to call, or `NULL` if the\n  thread-safe function is being torn down and `data` may need to be freed. It\n  may also be `NULL` if the thread-safe function was created without\n  `js_callback`.\n* `[in] context`: The optional data with which the thread-safe function was\n  created.\n* `[in] data`: Data created by the secondary thread. It is the responsibility of\n  the callback to convert this native data to JavaScript values (with Node-API\n  functions) that can be passed as parameters when `js_callback` is invoked.\n  This pointer is managed entirely by the threads and this callback. Thus this\n  callback should free the data.\n\nUnless for reasons discussed in [Object Lifetime Management](#object-lifetime-management), creating a\nhandle and/or callback scope inside the function body is not necessary.","summary":"Function pointer used with asynchronous thread-safe function calls. The callback will be called on the main thread. Its purpose is to use a data item arriving via the queue from one of the secondary threads to construct the parameters necessary for a call into JavaScript, usually via `napi_call_function`, and then make the call into JavaScript.","examples":[{"language":"c","displayName":null,"code":"typedef void (*napi_threadsafe_function_call_js)(napi_env env,\n                                                 napi_value js_callback,\n                                                 void* context,\n                                                 void* data);"}],"children":[]},{"kind":"section","id":"napi_cleanup_hook","name":"napi_cleanup_hook","title":"`napi_cleanup_hook`","scope":"module","overloadOf":null,"stability":null,"added":["v19.2.0","v18.13.0"],"deprecated":[],"removed":[],"napiVersion":[3],"changes":[],"description":"Function pointer used with [`napi_add_env_cleanup_hook`](#napi_add_env_cleanup_hook). It will be called\nwhen the environment is being torn down.\n\nCallback functions must satisfy the following signature:\n\n```c\ntypedef void (*napi_cleanup_hook)(void* data);\n```\n\n* `[in] data`: The data that was passed to [`napi_add_env_cleanup_hook`](#napi_add_env_cleanup_hook).","summary":"Function pointer used with `napi_add_env_cleanup_hook`. It will be called when the environment is being torn down.","examples":[{"language":"c","displayName":null,"code":"typedef void (*napi_cleanup_hook)(void* data);"}],"children":[]},{"kind":"section","id":"napi_async_cleanup_hook","name":"napi_async_cleanup_hook","title":"`napi_async_cleanup_hook`","scope":"module","overloadOf":null,"stability":null,"added":["v14.10.0","v12.19.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"Function pointer used with [`napi_add_async_cleanup_hook`](#napi_add_async_cleanup_hook). It will be called\nwhen the environment is being torn down.\n\nCallback functions must satisfy the following signature:\n\n```c\ntypedef void (*napi_async_cleanup_hook)(napi_async_cleanup_hook_handle handle,\n                                        void* data);\n```\n\n* `[in] handle`: The handle that must be passed to\n  [`napi_remove_async_cleanup_hook`](#napi_remove_async_cleanup_hook) after completion of the asynchronous\n  cleanup.\n* `[in] data`: The data that was passed to [`napi_add_async_cleanup_hook`](#napi_add_async_cleanup_hook).\n\nThe body of the function should initiate the asynchronous cleanup actions at the\nend of which `handle` must be passed in a call to\n[`napi_remove_async_cleanup_hook`](#napi_remove_async_cleanup_hook).","summary":"Function pointer used with `napi_add_async_cleanup_hook`. It will be called when the environment is being torn down.","examples":[{"language":"c","displayName":null,"code":"typedef void (*napi_async_cleanup_hook)(napi_async_cleanup_hook_handle handle,\n                                        void* data);"}],"children":[]}]}]},{"kind":"section","id":"error-handling","name":"Error handling","title":"Error handling","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"Node-API uses both return values and JavaScript exceptions for error handling.\nThe following sections explain the approach for each case.","summary":"Node-API uses both return values and JavaScript exceptions for error handling. The following sections explain the approach for each case.","examples":[],"children":[{"kind":"section","id":"return-values","name":"Return values","title":"Return values","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"All of the Node-API functions share the same error handling pattern. The\nreturn type of all API functions is `napi_status`.\n\nThe return value will be `napi_ok` if the request was successful and\nno uncaught JavaScript exception was thrown. If an error occurred AND\nan exception was thrown, the `napi_status` value for the error\nwill be returned. If an exception was thrown, and no error occurred,\n`napi_pending_exception` will be returned.\n\nIn cases where a return value other than `napi_ok` or\n`napi_pending_exception` is returned, [`napi_is_exception_pending`](#napi_is_exception_pending)\nmust be called to check if an exception is pending.\nSee the section on exceptions for more details.\n\nThe full set of possible `napi_status` values is defined\nin `napi_api_types.h`.\n\nThe `napi_status` return value provides a VM-independent representation of\nthe error which occurred. In some cases it is useful to be able to get\nmore detailed information, including a string representing the error as well as\nVM (engine)-specific information.\n\nIn order to retrieve this information [`napi_get_last_error_info`](#napi_get_last_error_info)\nis provided which returns a `napi_extended_error_info` structure.\nThe format of the `napi_extended_error_info` structure is as follows:\n\n```c\ntypedef struct napi_extended_error_info {\n  const char* error_message;\n  void* engine_reserved;\n  uint32_t engine_error_code;\n  napi_status error_code;\n};\n```\n\n* `error_message`: Textual representation of the error that occurred.\n* `engine_reserved`: Opaque handle reserved for engine use only.\n* `engine_error_code`: VM specific error code.\n* `error_code`: Node-API status code for the last error.\n\n[`napi_get_last_error_info`](#napi_get_last_error_info) returns the information for the last\nNode-API call that was made.\n\nDo not rely on the content or format of any of the extended information as it\nis not subject to SemVer and may change at any time. It is intended only for\nlogging purposes.","summary":"All of the Node-API functions share the same error handling pattern. The return type of all API functions is `napi_status`.","examples":[{"language":"c","displayName":null,"code":"typedef struct napi_extended_error_info {\n  const char* error_message;\n  void* engine_reserved;\n  uint32_t engine_error_code;\n  napi_status error_code;\n};"}],"children":[{"kind":"section","id":"napi_get_last_error_info","name":"napi_get_last_error_info","title":"`napi_get_last_error_info`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status\nnapi_get_last_error_info(node_api_basic_env env,\n                         const napi_extended_error_info** result);\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[out] result`: The `napi_extended_error_info` structure with more\n  information about the error.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API retrieves a `napi_extended_error_info` structure with information\nabout the last error that occurred.\n\nThe content of the `napi_extended_error_info` returned is only valid up until\na Node-API function is called on the same `env`. This includes a call to\n`napi_is_exception_pending` so it may often be necessary to make a copy\nof the information so that it can be used later. The pointer returned\nin `error_message` points to a statically-defined string so it is safe to use\nthat pointer if you have copied it out of the `error_message` field (which will\nbe overwritten) before another Node-API function was called.\n\nDo not rely on the content or format of any of the extended information as it\nis not subject to SemVer and may change at any time. It is intended only for\nlogging purposes.\n\nThis API can be called even if there is a pending JavaScript exception.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status\nnapi_get_last_error_info(node_api_basic_env env,\n                         const napi_extended_error_info** result);"}],"children":[]}]},{"kind":"section","id":"exceptions","name":"Exceptions","title":"Exceptions","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"Any Node-API function call may result in a pending JavaScript exception. This is\nthe case for any of the API functions, even those that may not cause the\nexecution of JavaScript.\n\nIf the `napi_status` returned by a function is `napi_ok` then no\nexception is pending and no additional action is required. If the\n`napi_status` returned is anything other than `napi_ok` or\n`napi_pending_exception`, in order to try to recover and continue\ninstead of simply returning immediately, [`napi_is_exception_pending`](#napi_is_exception_pending)\nmust be called in order to determine if an exception is pending or not.\n\nIn many cases when a Node-API function is called and an exception is\nalready pending, the function will return immediately with a\n`napi_status` of `napi_pending_exception`. However, this is not the case\nfor all functions. Node-API allows a subset of the functions to be\ncalled to allow for some minimal cleanup before returning to JavaScript.\nIn that case, `napi_status` will reflect the status for the function. It\nwill not reflect previous pending exceptions. To avoid confusion, check\nthe error status after every function call.\n\nWhen an exception is pending one of two approaches can be employed.\n\nThe first approach is to do any appropriate cleanup and then return so that\nexecution will return to JavaScript. As part of the transition back to\nJavaScript, the exception will be thrown at the point in the JavaScript\ncode where the native method was invoked. The behavior of most Node-API calls\nis unspecified while an exception is pending, and many will simply return\n`napi_pending_exception`, so do as little as possible and then return to\nJavaScript where the exception can be handled.\n\nThe second approach is to try to handle the exception. There will be cases\nwhere the native code can catch the exception, take the appropriate action,\nand then continue. This is only recommended in specific cases\nwhere it is known that the exception can be safely handled. In these\ncases [`napi_get_and_clear_last_exception`](#napi_get_and_clear_last_exception) can be used to get and\nclear the exception. On success, result will contain the handle to\nthe last JavaScript `Object` thrown. If it is determined, after\nretrieving the exception, the exception cannot be handled after all\nit can be re-thrown it with [`napi_throw`](#napi_throw) where error is the\nJavaScript value to be thrown.\n\nThe following utility functions are also available in case native code\nneeds to throw an exception or determine if a `napi_value` is an instance\nof a JavaScript `Error` object: [`napi_throw_error`](#napi_throw_error),\n[`napi_throw_type_error`](#napi_throw_type_error), [`napi_throw_range_error`](#napi_throw_range_error), [`node_api_throw_syntax_error`](#node_api_throw_syntax_error) and [`napi_is_error`](#napi_is_error).\n\nThe following utility functions are also available in case native\ncode needs to create an `Error` object: [`napi_create_error`](#napi_create_error),\n[`napi_create_type_error`](#napi_create_type_error), [`napi_create_range_error`](#napi_create_range_error) and [`node_api_create_syntax_error`](#node_api_create_syntax_error),\nwhere result is the `napi_value` that refers to the newly created\nJavaScript `Error` object.\n\nThe Node.js project is adding error codes to all of the errors\ngenerated internally. The goal is for applications to use these\nerror codes for all error checking. The associated error messages\nwill remain, but will only be meant to be used for logging and\ndisplay with the expectation that the message can change without\nSemVer applying. In order to support this model with Node-API, both\nin internal functionality and for module specific functionality\n(as its good practice), the `throw_` and `create_` functions\ntake an optional code parameter which is the string for the code\nto be added to the error object. If the optional parameter is `NULL`\nthen no code will be associated with the error. If a code is provided,\nthe name associated with the error is also updated to be:\n\n```text\noriginalName [code]\n```\n\nwhere `originalName` is the original name associated with the error\nand `code` is the code that was provided. For example, if the code\nis `'ERR_ERROR_1'` and a `TypeError` is being created the name will be:\n\n```text\nTypeError [ERR_ERROR_1]\n```","summary":"Any Node-API function call may result in a pending JavaScript exception. This is the case for any of the API functions, even those that may not cause the execution of JavaScript.","examples":[{"language":"text","displayName":null,"code":"originalName [code]"},{"language":"text","displayName":null,"code":"TypeError [ERR_ERROR_1]"}],"children":[{"kind":"section","id":"napi_throw","name":"napi_throw","title":"`napi_throw`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nNAPI_EXTERN napi_status napi_throw(napi_env env, napi_value error);\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] error`: The JavaScript value to be thrown.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API throws the JavaScript value provided.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"NAPI_EXTERN napi_status napi_throw(napi_env env, napi_value error);"}],"children":[]},{"kind":"section","id":"napi_throw_error","name":"napi_throw_error","title":"`napi_throw_error`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nNAPI_EXTERN napi_status napi_throw_error(napi_env env,\n                                         const char* code,\n                                         const char* msg);\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] code`: Optional error code to be set on the error.\n* `[in] msg`: C string representing the text to be associated with the error.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API throws a JavaScript `Error` with the text provided.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"NAPI_EXTERN napi_status napi_throw_error(napi_env env,\n                                         const char* code,\n                                         const char* msg);"}],"children":[]},{"kind":"section","id":"napi_throw_type_error","name":"napi_throw_type_error","title":"`napi_throw_type_error`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nNAPI_EXTERN napi_status napi_throw_type_error(napi_env env,\n                                              const char* code,\n                                              const char* msg);\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] code`: Optional error code to be set on the error.\n* `[in] msg`: C string representing the text to be associated with the error.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API throws a JavaScript `TypeError` with the text provided.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"NAPI_EXTERN napi_status napi_throw_type_error(napi_env env,\n                                              const char* code,\n                                              const char* msg);"}],"children":[]},{"kind":"section","id":"napi_throw_range_error","name":"napi_throw_range_error","title":"`napi_throw_range_error`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nNAPI_EXTERN napi_status napi_throw_range_error(napi_env env,\n                                               const char* code,\n                                               const char* msg);\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] code`: Optional error code to be set on the error.\n* `[in] msg`: C string representing the text to be associated with the error.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API throws a JavaScript `RangeError` with the text provided.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"NAPI_EXTERN napi_status napi_throw_range_error(napi_env env,\n                                               const char* code,\n                                               const char* msg);"}],"children":[]},{"kind":"section","id":"node_api_throw_syntax_error","name":"node_api_throw_syntax_error","title":"`node_api_throw_syntax_error`","scope":"module","overloadOf":null,"stability":null,"added":["v17.2.0","v16.14.0"],"deprecated":[],"removed":[],"napiVersion":[9],"changes":[],"description":"```c\nNAPI_EXTERN napi_status node_api_throw_syntax_error(napi_env env,\n                                                    const char* code,\n                                                    const char* msg);\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] code`: Optional error code to be set on the error.\n* `[in] msg`: C string representing the text to be associated with the error.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API throws a JavaScript `SyntaxError` with the text provided.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"NAPI_EXTERN napi_status node_api_throw_syntax_error(napi_env env,\n                                                    const char* code,\n                                                    const char* msg);"}],"children":[]},{"kind":"section","id":"napi_is_error","name":"napi_is_error","title":"`napi_is_error`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nNAPI_EXTERN napi_status napi_is_error(napi_env env,\n                                      napi_value value,\n                                      bool* result);\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] value`: The `napi_value` to be checked.\n* `[out] result`: Boolean value that is set to true if `napi_value` represents\n  an error, false otherwise.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API queries a `napi_value` to check if it represents an error object.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"NAPI_EXTERN napi_status napi_is_error(napi_env env,\n                                      napi_value value,\n                                      bool* result);"}],"children":[]},{"kind":"section","id":"napi_create_error","name":"napi_create_error","title":"`napi_create_error`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nNAPI_EXTERN napi_status napi_create_error(napi_env env,\n                                          napi_value code,\n                                          napi_value msg,\n                                          napi_value* result);\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] code`: Optional `napi_value` with the string for the error code to be\n  associated with the error.\n* `[in] msg`: `napi_value` that references a JavaScript `string` to be used as\n  the message for the `Error`.\n* `[out] result`: `napi_value` representing the error created.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API returns a JavaScript `Error` with the text provided.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"NAPI_EXTERN napi_status napi_create_error(napi_env env,\n                                          napi_value code,\n                                          napi_value msg,\n                                          napi_value* result);"}],"children":[]},{"kind":"section","id":"napi_create_type_error","name":"napi_create_type_error","title":"`napi_create_type_error`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nNAPI_EXTERN napi_status napi_create_type_error(napi_env env,\n                                               napi_value code,\n                                               napi_value msg,\n                                               napi_value* result);\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] code`: Optional `napi_value` with the string for the error code to be\n  associated with the error.\n* `[in] msg`: `napi_value` that references a JavaScript `string` to be used as\n  the message for the `Error`.\n* `[out] result`: `napi_value` representing the error created.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API returns a JavaScript `TypeError` with the text provided.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"NAPI_EXTERN napi_status napi_create_type_error(napi_env env,\n                                               napi_value code,\n                                               napi_value msg,\n                                               napi_value* result);"}],"children":[]},{"kind":"section","id":"napi_create_range_error","name":"napi_create_range_error","title":"`napi_create_range_error`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nNAPI_EXTERN napi_status napi_create_range_error(napi_env env,\n                                                napi_value code,\n                                                napi_value msg,\n                                                napi_value* result);\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] code`: Optional `napi_value` with the string for the error code to be\n  associated with the error.\n* `[in] msg`: `napi_value` that references a JavaScript `string` to be used as\n  the message for the `Error`.\n* `[out] result`: `napi_value` representing the error created.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API returns a JavaScript `RangeError` with the text provided.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"NAPI_EXTERN napi_status napi_create_range_error(napi_env env,\n                                                napi_value code,\n                                                napi_value msg,\n                                                napi_value* result);"}],"children":[]},{"kind":"section","id":"node_api_create_syntax_error","name":"node_api_create_syntax_error","title":"`node_api_create_syntax_error`","scope":"module","overloadOf":null,"stability":null,"added":["v17.2.0","v16.14.0"],"deprecated":[],"removed":[],"napiVersion":[9],"changes":[],"description":"```c\nNAPI_EXTERN napi_status node_api_create_syntax_error(napi_env env,\n                                                     napi_value code,\n                                                     napi_value msg,\n                                                     napi_value* result);\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] code`: Optional `napi_value` with the string for the error code to be\n  associated with the error.\n* `[in] msg`: `napi_value` that references a JavaScript `string` to be used as\n  the message for the `Error`.\n* `[out] result`: `napi_value` representing the error created.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API returns a JavaScript `SyntaxError` with the text provided.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"NAPI_EXTERN napi_status node_api_create_syntax_error(napi_env env,\n                                                     napi_value code,\n                                                     napi_value msg,\n                                                     napi_value* result);"}],"children":[]},{"kind":"section","id":"napi_get_and_clear_last_exception","name":"napi_get_and_clear_last_exception","title":"`napi_get_and_clear_last_exception`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_get_and_clear_last_exception(napi_env env,\n                                              napi_value* result);\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[out] result`: The exception if one is pending, `NULL` otherwise.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API can be called even if there is a pending JavaScript exception.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_get_and_clear_last_exception(napi_env env,\n                                              napi_value* result);"}],"children":[]},{"kind":"section","id":"napi_is_exception_pending","name":"napi_is_exception_pending","title":"`napi_is_exception_pending`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_is_exception_pending(napi_env env, bool* result);\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[out] result`: Boolean value that is set to true if an exception is pending.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API can be called even if there is a pending JavaScript exception.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_is_exception_pending(napi_env env, bool* result);"}],"children":[]},{"kind":"section","id":"napi_fatal_exception","name":"napi_fatal_exception","title":"`napi_fatal_exception`","scope":"module","overloadOf":null,"stability":null,"added":["v9.10.0"],"deprecated":[],"removed":[],"napiVersion":[3],"changes":[],"description":"```c\nnapi_status napi_fatal_exception(napi_env env, napi_value err);\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] err`: The error that is passed to `'uncaughtException'`.\n\nTrigger an `'uncaughtException'` in JavaScript. Useful if an async\ncallback throws an exception with no way to recover.","summary":"Trigger an `'uncaughtException'` in JavaScript. Useful if an async callback throws an exception with no way to recover.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_fatal_exception(napi_env env, napi_value err);"}],"children":[]}]},{"kind":"section","id":"fatal-errors","name":"Fatal errors","title":"Fatal errors","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"In the event of an unrecoverable error in a native addon, a fatal error can be\nthrown to immediately terminate the process.","summary":"In the event of an unrecoverable error in a native addon, a fatal error can be thrown to immediately terminate the process.","examples":[],"children":[{"kind":"section","id":"napi_fatal_error","name":"napi_fatal_error","title":"`napi_fatal_error`","scope":"module","overloadOf":null,"stability":null,"added":["v8.2.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nNAPI_NO_RETURN void napi_fatal_error(const char* location,\n                                     size_t location_len,\n                                     const char* message,\n                                     size_t message_len);\n```\n\n* `[in] location`: Optional location at which the error occurred.\n* `[in] location_len`: The length of the location in bytes, or\n  `NAPI_AUTO_LENGTH` if it is null-terminated.\n* `[in] message`: The message associated with the error.\n* `[in] message_len`: The length of the message in bytes, or `NAPI_AUTO_LENGTH`\n  if it is null-terminated.\n\nThe function call does not return, the process will be terminated.\n\nThis API can be called even if there is a pending JavaScript exception.","summary":"The function call does not return, the process will be terminated.","examples":[{"language":"c","displayName":null,"code":"NAPI_NO_RETURN void napi_fatal_error(const char* location,\n                                     size_t location_len,\n                                     const char* message,\n                                     size_t message_len);"}],"children":[]}]}]},{"kind":"section","id":"object-lifetime-management","name":"Object lifetime management","title":"Object lifetime management","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"As Node-API calls are made, handles to objects in the heap for the underlying\nVM may be returned as `napi_values`. These handles must hold the\nobjects 'live' until they are no longer required by the native code,\notherwise the objects could be collected before the native code was\nfinished using them.\n\nAs object handles are returned they are associated with a\n'scope'. The lifespan for the default scope is tied to the lifespan\nof the native method call. The result is that, by default, handles\nremain valid and the objects associated with these handles will be\nheld live for the lifespan of the native method call.\n\nIn many cases, however, it is necessary that the handles remain valid for\neither a shorter or longer lifespan than that of the native method.\nThe sections which follow describe the Node-API functions that can be used\nto change the handle lifespan from the default.","summary":"As Node-API calls are made, handles to objects in the heap for the underlying VM may be returned as `napi_values`. These handles must hold the objects 'live' until they are no longer required by the native code, otherwise the objects could be collected before the native code was finished using them.","examples":[],"children":[{"kind":"section","id":"making-handle-lifespan-shorter-than-that-of-the-native-method","name":"Making handle lifespan shorter than that of the native method","title":"Making handle lifespan shorter than that of the native method","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"It is often necessary to make the lifespan of handles shorter than\nthe lifespan of a native method. For example, consider a native method\nthat has a loop which iterates through the elements in a large array:\n\n```c\nfor (int i = 0; i < 1000000; i++) {\n  napi_value result;\n  napi_status status = napi_get_element(env, object, i, &result);\n  if (status != napi_ok) {\n    break;\n  }\n  // do something with element\n}\n```\n\nThis would result in a large number of handles being created, consuming\nsubstantial resources. In addition, even though the native code could only\nuse the most recent handle, all of the associated objects would also be\nkept alive since they all share the same scope.\n\nTo handle this case, Node-API provides the ability to establish a new 'scope' to\nwhich newly created handles will be associated. Once those handles\nare no longer required, the scope can be 'closed' and any handles associated\nwith the scope are invalidated. The methods available to open/close scopes are\n[`napi_open_handle_scope`](#napi_open_handle_scope) and [`napi_close_handle_scope`](#napi_close_handle_scope).\n\nNode-API only supports a single nested hierarchy of scopes. There is only one\nactive scope at any time, and all new handles will be associated with that\nscope while it is active. Scopes must be closed in the reverse order from\nwhich they are opened. In addition, all scopes created within a native method\nmust be closed before returning from that method.\n\nTaking the earlier example, adding calls to [`napi_open_handle_scope`](#napi_open_handle_scope) and\n[`napi_close_handle_scope`](#napi_close_handle_scope) would ensure that at most a single handle\nis valid throughout the execution of the loop:\n\n```c\nfor (int i = 0; i < 1000000; i++) {\n  napi_handle_scope scope;\n  napi_status status = napi_open_handle_scope(env, &scope);\n  if (status != napi_ok) {\n    break;\n  }\n  napi_value result;\n  status = napi_get_element(env, object, i, &result);\n  if (status != napi_ok) {\n    break;\n  }\n  // do something with element\n  status = napi_close_handle_scope(env, scope);\n  if (status != napi_ok) {\n    break;\n  }\n}\n```\n\nWhen nesting scopes, there are cases where a handle from an\ninner scope needs to live beyond the lifespan of that scope. Node-API supports\nan 'escapable scope' in order to support this case. An escapable scope\nallows one handle to be 'promoted' so that it 'escapes' the\ncurrent scope and the lifespan of the handle changes from the current\nscope to that of the outer scope.\n\nThe methods available to open/close escapable scopes are\n[`napi_open_escapable_handle_scope`](#napi_open_escapable_handle_scope) and\n[`napi_close_escapable_handle_scope`](#napi_close_escapable_handle_scope).\n\nThe request to promote a handle is made through [`napi_escape_handle`](#napi_escape_handle) which\ncan only be called once.","summary":"It is often necessary to make the lifespan of handles shorter than the lifespan of a native method. For example, consider a native method that has a loop which iterates through the elements in a large array:","examples":[{"language":"c","displayName":null,"code":"for (int i = 0; i < 1000000; i++) {\n  napi_value result;\n  napi_status status = napi_get_element(env, object, i, &result);\n  if (status != napi_ok) {\n    break;\n  }\n  // do something with element\n}"},{"language":"c","displayName":null,"code":"for (int i = 0; i < 1000000; i++) {\n  napi_handle_scope scope;\n  napi_status status = napi_open_handle_scope(env, &scope);\n  if (status != napi_ok) {\n    break;\n  }\n  napi_value result;\n  status = napi_get_element(env, object, i, &result);\n  if (status != napi_ok) {\n    break;\n  }\n  // do something with element\n  status = napi_close_handle_scope(env, scope);\n  if (status != napi_ok) {\n    break;\n  }\n}"}],"children":[{"kind":"section","id":"napi_open_handle_scope","name":"napi_open_handle_scope","title":"`napi_open_handle_scope`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nNAPI_EXTERN napi_status napi_open_handle_scope(napi_env env,\n                                               napi_handle_scope* result);\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[out] result`: `napi_value` representing the new scope.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API opens a new scope.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"NAPI_EXTERN napi_status napi_open_handle_scope(napi_env env,\n                                               napi_handle_scope* result);"}],"children":[]},{"kind":"section","id":"napi_close_handle_scope","name":"napi_close_handle_scope","title":"`napi_close_handle_scope`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nNAPI_EXTERN napi_status napi_close_handle_scope(napi_env env,\n                                                napi_handle_scope scope);\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] scope`: `napi_value` representing the scope to be closed.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API closes the scope passed in. Scopes must be closed in the\nreverse order from which they were created.\n\nThis API can be called even if there is a pending JavaScript exception.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"NAPI_EXTERN napi_status napi_close_handle_scope(napi_env env,\n                                                napi_handle_scope scope);"}],"children":[]},{"kind":"section","id":"napi_open_escapable_handle_scope","name":"napi_open_escapable_handle_scope","title":"`napi_open_escapable_handle_scope`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nNAPI_EXTERN napi_status\n    napi_open_escapable_handle_scope(napi_env env,\n                                     napi_handle_scope* result);\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[out] result`: `napi_value` representing the new scope.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API opens a new scope from which one object can be promoted\nto the outer scope.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"NAPI_EXTERN napi_status\n    napi_open_escapable_handle_scope(napi_env env,\n                                     napi_handle_scope* result);"}],"children":[]},{"kind":"section","id":"napi_close_escapable_handle_scope","name":"napi_close_escapable_handle_scope","title":"`napi_close_escapable_handle_scope`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nNAPI_EXTERN napi_status\n    napi_close_escapable_handle_scope(napi_env env,\n                                      napi_handle_scope scope);\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] scope`: `napi_value` representing the scope to be closed.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API closes the scope passed in. Scopes must be closed in the\nreverse order from which they were created.\n\nThis API can be called even if there is a pending JavaScript exception.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"NAPI_EXTERN napi_status\n    napi_close_escapable_handle_scope(napi_env env,\n                                      napi_handle_scope scope);"}],"children":[]},{"kind":"section","id":"napi_escape_handle","name":"napi_escape_handle","title":"`napi_escape_handle`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_escape_handle(napi_env env,\n                               napi_escapable_handle_scope scope,\n                               napi_value escapee,\n                               napi_value* result);\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] scope`: `napi_value` representing the current scope.\n* `[in] escapee`: `napi_value` representing the JavaScript `Object` to be\n  escaped.\n* `[out] result`: `napi_value` representing the handle to the escaped `Object`\n  in the outer scope.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API promotes the handle to the JavaScript object so that it is valid\nfor the lifetime of the outer scope. It can only be called once per scope.\nIf it is called more than once an error will be returned.\n\nThis API can be called even if there is a pending JavaScript exception.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_escape_handle(napi_env env,\n                               napi_escapable_handle_scope scope,\n                               napi_value escapee,\n                               napi_value* result);"}],"children":[]}]},{"kind":"section","id":"references-to-values-with-a-lifespan-longer-than-that-of-the-native-method","name":"References to values with a lifespan longer than that of the native method","title":"References to values with a lifespan longer than that of the native method","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"In some cases, an addon will need to be able to create and reference values\nwith a lifespan longer than that of a single native method invocation. For\nexample, to create a constructor and later use that constructor\nin a request to create instances, it must be possible to reference\nthe constructor object across many different instance creation requests. This\nwould not be possible with a normal handle returned as a `napi_value` as\ndescribed in the earlier section. The lifespan of a normal handle is\nmanaged by scopes and all scopes must be closed before the end of a native\nmethod.\n\nNode-API provides methods for creating persistent references to values.\nCurrently Node-API only allows references to be created for a\nlimited set of value types, including object, external, function, and symbol.\n\nEach reference has an associated count with a value of 0 or higher,\nwhich determines whether the reference will keep the corresponding value alive.\nReferences with a count of 0 do not prevent values from being collected.\nValues of object (object, function, external) and symbol types are becoming\n'weak' references and can still be accessed while they are not collected.\nAny count greater than 0 will prevent the values from being collected.\n\nSymbol values have different flavors. The true weak reference behavior is\nonly supported by local symbols created with the `napi_create_symbol` function\nor the JavaScript `Symbol()` constructor calls. Globally registered symbols\ncreated with the `node_api_symbol_for` function or JavaScript `Symbol.for()`\nfunction calls remain always strong references because the garbage collector\ndoes not collect them. The same is true for well-known symbols such as\n`Symbol.iterator`. They are also never collected by the garbage collector.\n\nReferences can be created with an initial reference count. The count can\nthen be modified through [`napi_reference_ref`](#napi_reference_ref) and\n[`napi_reference_unref`](#napi_reference_unref). If an object is collected while the count\nfor a reference is 0, all subsequent calls to\nget the object associated with the reference [`napi_get_reference_value`](#napi_get_reference_value)\nwill return `NULL` for the returned `napi_value`. An attempt to call\n[`napi_reference_ref`](#napi_reference_ref) for a reference whose object has been collected\nresults in an error.\n\nReferences must be deleted once they are no longer required by the addon. When\na reference is deleted, it will no longer prevent the corresponding object from\nbeing collected. Failure to delete a persistent reference results in\na 'memory leak' with both the native memory for the persistent reference and\nthe corresponding object on the heap being retained forever.\n\nThere can be multiple persistent references created which refer to the same\nobject, each of which will either keep the object live or not based on its\nindividual count. Multiple persistent references to the same object\ncan result in unexpectedly keeping alive native memory. The native structures\nfor a persistent reference must be kept alive until finalizers for the\nreferenced object are executed. If a new persistent reference is created\nfor the same object, the finalizers for that object will not be\nrun and the native memory pointed by the earlier persistent reference\nwill not be freed. This can be avoided by calling\n`napi_delete_reference` in addition to `napi_reference_unref` when possible.\n\n**Change History:**\n\n* Version 10 (`NAPI_VERSION` is defined as `10` or higher):\n\n  References can be created for all value types. The new supported value\n  types do not support weak reference semantic and the values of these types\n  are released when the reference count becomes 0 and cannot be accessed from\n  the reference anymore.","summary":"In some cases, an addon will need to be able to create and reference values with a lifespan longer than that of a single native method invocation. For example, to create a constructor and later use that constructor in a request to create instances, it must be possible to reference the constructor object across many different instance creation requests. This would not be possible with a normal handle returned as a `napi_value` as described in the earlier section. The lifespan of a normal handle is managed by scopes and all scopes must be closed before the end of a native method.","examples":[],"children":[{"kind":"section","id":"napi_create_reference","name":"napi_create_reference","title":"`napi_create_reference`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nNAPI_EXTERN napi_status napi_create_reference(napi_env env,\n                                              napi_value value,\n                                              uint32_t initial_refcount,\n                                              napi_ref* result);\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] value`: The `napi_value` for which a reference is being created.\n* `[in] initial_refcount`: Initial reference count for the new reference.\n* `[out] result`: `napi_ref` pointing to the new reference.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API creates a new reference with the specified reference count\nto the value passed in.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"NAPI_EXTERN napi_status napi_create_reference(napi_env env,\n                                              napi_value value,\n                                              uint32_t initial_refcount,\n                                              napi_ref* result);"}],"children":[]},{"kind":"section","id":"napi_delete_reference","name":"napi_delete_reference","title":"`napi_delete_reference`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nNAPI_EXTERN napi_status napi_delete_reference(napi_env env, napi_ref ref);\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] ref`: `napi_ref` to be deleted.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API deletes the reference passed in.\n\nThis API can be called even if there is a pending JavaScript exception.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"NAPI_EXTERN napi_status napi_delete_reference(napi_env env, napi_ref ref);"}],"children":[]},{"kind":"section","id":"napi_reference_ref","name":"napi_reference_ref","title":"`napi_reference_ref`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nNAPI_EXTERN napi_status napi_reference_ref(napi_env env,\n                                           napi_ref ref,\n                                           uint32_t* result);\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] ref`: `napi_ref` for which the reference count will be incremented.\n* `[out] result`: The new reference count.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API increments the reference count for the reference\npassed in and returns the resulting reference count.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"NAPI_EXTERN napi_status napi_reference_ref(napi_env env,\n                                           napi_ref ref,\n                                           uint32_t* result);"}],"children":[]},{"kind":"section","id":"napi_reference_unref","name":"napi_reference_unref","title":"`napi_reference_unref`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nNAPI_EXTERN napi_status napi_reference_unref(napi_env env,\n                                             napi_ref ref,\n                                             uint32_t* result);\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] ref`: `napi_ref` for which the reference count will be decremented.\n* `[out] result`: The new reference count.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API decrements the reference count for the reference\npassed in and returns the resulting reference count.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"NAPI_EXTERN napi_status napi_reference_unref(napi_env env,\n                                             napi_ref ref,\n                                             uint32_t* result);"}],"children":[]},{"kind":"section","id":"napi_get_reference_value","name":"napi_get_reference_value","title":"`napi_get_reference_value`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nNAPI_EXTERN napi_status napi_get_reference_value(napi_env env,\n                                                 napi_ref ref,\n                                                 napi_value* result);\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] ref`: The `napi_ref` for which the corresponding value is\n  being requested.\n* `[out] result`: The `napi_value` referenced by the `napi_ref`.\n\nReturns `napi_ok` if the API succeeded.\n\nIf still valid, this API returns the `napi_value` representing the\nJavaScript value associated with the `napi_ref`. Otherwise, result\nwill be `NULL`.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"NAPI_EXTERN napi_status napi_get_reference_value(napi_env env,\n                                                 napi_ref ref,\n                                                 napi_value* result);"}],"children":[]}]},{"kind":"section","id":"cleanup-on-exit-of-the-current-nodejs-environment","name":"Cleanup on exit of the current Node.js environment","title":"Cleanup on exit of the current Node.js environment","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"While a Node.js process typically releases all its resources when exiting,\nembedders of Node.js, or future Worker support, may require addons to register\nclean-up hooks that will be run once the current Node.js environment exits.\n\nNode-API provides functions for registering and un-registering such callbacks.\nWhen those callbacks are run, all resources that are being held by the addon\nshould be freed up.","summary":"While a Node.js process typically releases all its resources when exiting, embedders of Node.js, or future Worker support, may require addons to register clean-up hooks that will be run once the current Node.js environment exits.","examples":[],"children":[{"kind":"section","id":"napi_add_env_cleanup_hook","name":"napi_add_env_cleanup_hook","title":"`napi_add_env_cleanup_hook`","scope":"module","overloadOf":null,"stability":null,"added":["v10.2.0"],"deprecated":[],"removed":[],"napiVersion":[3],"changes":[],"description":"```c\nNODE_EXTERN napi_status napi_add_env_cleanup_hook(node_api_basic_env env,\n                                                  napi_cleanup_hook fun,\n                                                  void* arg);\n```\n\nRegisters `fun` as a function to be run with the `arg` parameter once the\ncurrent Node.js environment exits.\n\nA function can safely be specified multiple times with different\n`arg` values. In that case, it will be called multiple times as well.\nProviding the same `fun` and `arg` values multiple times is not allowed\nand will lead the process to abort.\n\nThe hooks will be called in reverse order, i.e. the most recently added one\nwill be called first.\n\nRemoving this hook can be done by using [`napi_remove_env_cleanup_hook`](#napi_remove_env_cleanup_hook).\nTypically, that happens when the resource for which this hook was added\nis being torn down anyway.\n\nFor asynchronous cleanup, [`napi_add_async_cleanup_hook`](#napi_add_async_cleanup_hook) is available.","summary":"Registers `fun` as a function to be run with the `arg` parameter once the current Node.js environment exits.","examples":[{"language":"c","displayName":null,"code":"NODE_EXTERN napi_status napi_add_env_cleanup_hook(node_api_basic_env env,\n                                                  napi_cleanup_hook fun,\n                                                  void* arg);"}],"children":[]},{"kind":"section","id":"napi_remove_env_cleanup_hook","name":"napi_remove_env_cleanup_hook","title":"`napi_remove_env_cleanup_hook`","scope":"module","overloadOf":null,"stability":null,"added":["v10.2.0"],"deprecated":[],"removed":[],"napiVersion":[3],"changes":[],"description":"```c\nNAPI_EXTERN napi_status napi_remove_env_cleanup_hook(node_api_basic_env env,\n                                                     void (*fun)(void* arg),\n                                                     void* arg);\n```\n\nUnregisters `fun` as a function to be run with the `arg` parameter once the\ncurrent Node.js environment exits. Both the argument and the function value\nneed to be exact matches.\n\nThe function must have originally been registered\nwith `napi_add_env_cleanup_hook`, otherwise the process will abort.","summary":"Unregisters `fun` as a function to be run with the `arg` parameter once the current Node.js environment exits. Both the argument and the function value need to be exact matches.","examples":[{"language":"c","displayName":null,"code":"NAPI_EXTERN napi_status napi_remove_env_cleanup_hook(node_api_basic_env env,\n                                                     void (*fun)(void* arg),\n                                                     void* arg);"}],"children":[]},{"kind":"section","id":"napi_add_async_cleanup_hook","name":"napi_add_async_cleanup_hook","title":"`napi_add_async_cleanup_hook`","scope":"module","overloadOf":null,"stability":null,"added":["v14.8.0","v12.19.0"],"deprecated":[],"removed":[],"napiVersion":[8],"changes":[{"versions":["v14.10.0","v12.19.0"],"prUrl":"https://github.com/nodejs/node/pull/34819","commit":null,"description":"Changed signature of the `hook` callback."}],"description":"```c\nNAPI_EXTERN napi_status napi_add_async_cleanup_hook(\n    node_api_basic_env env,\n    napi_async_cleanup_hook hook,\n    void* arg,\n    napi_async_cleanup_hook_handle* remove_handle);\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] hook`: The function pointer to call at environment teardown.\n* `[in] arg`: The pointer to pass to `hook` when it gets called.\n* `[out] remove_handle`: Optional handle that refers to the asynchronous cleanup\n  hook.\n\nRegisters `hook`, which is a function of type [`napi_async_cleanup_hook`](#napi_async_cleanup_hook), as\na function to be run with the `remove_handle` and `arg` parameters once the\ncurrent Node.js environment exits.\n\nUnlike [`napi_add_env_cleanup_hook`](#napi_add_env_cleanup_hook), the hook is allowed to be asynchronous.\n\nOtherwise, behavior generally matches that of [`napi_add_env_cleanup_hook`](#napi_add_env_cleanup_hook).\n\nIf `remove_handle` is not `NULL`, an opaque value will be stored in it\nthat must later be passed to [`napi_remove_async_cleanup_hook`](#napi_remove_async_cleanup_hook),\nregardless of whether the hook has already been invoked.\nTypically, that happens when the resource for which this hook was added\nis being torn down anyway.","summary":"Registers `hook`, which is a function of type `napi_async_cleanup_hook`, as a function to be run with the `remove_handle` and `arg` parameters once the current Node.js environment exits.","examples":[{"language":"c","displayName":null,"code":"NAPI_EXTERN napi_status napi_add_async_cleanup_hook(\n    node_api_basic_env env,\n    napi_async_cleanup_hook hook,\n    void* arg,\n    napi_async_cleanup_hook_handle* remove_handle);"}],"children":[]},{"kind":"section","id":"napi_remove_async_cleanup_hook","name":"napi_remove_async_cleanup_hook","title":"`napi_remove_async_cleanup_hook`","scope":"module","overloadOf":null,"stability":null,"added":["v14.8.0","v12.19.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v14.10.0","v12.19.0"],"prUrl":"https://github.com/nodejs/node/pull/34819","commit":null,"description":"Removed `env` parameter."}],"description":"```c\nNAPI_EXTERN napi_status napi_remove_async_cleanup_hook(\n    napi_async_cleanup_hook_handle remove_handle);\n```\n\n* `[in] remove_handle`: The handle to an asynchronous cleanup hook that was\n  created with [`napi_add_async_cleanup_hook`](#napi_add_async_cleanup_hook).\n\nUnregisters the cleanup hook corresponding to `remove_handle`. This will prevent\nthe hook from being executed, unless it has already started executing.\nThis must be called on any `napi_async_cleanup_hook_handle` value obtained\nfrom [`napi_add_async_cleanup_hook`](#napi_add_async_cleanup_hook).","summary":"Unregisters the cleanup hook corresponding to `remove_handle`. This will prevent the hook from being executed, unless it has already started executing. This must be called on any `napi_async_cleanup_hook_handle` value obtained from `napi_add_async_cleanup_hook`.","examples":[{"language":"c","displayName":null,"code":"NAPI_EXTERN napi_status napi_remove_async_cleanup_hook(\n    napi_async_cleanup_hook_handle remove_handle);"}],"children":[]}]},{"kind":"section","id":"finalization-on-the-exit-of-the-nodejs-environment","name":"Finalization on the exit of the Node.js environment","title":"Finalization on the exit of the Node.js environment","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"The Node.js environment may be torn down at an arbitrary time as soon as\npossible with JavaScript execution disallowed, like on the request of\n[`worker.terminate()`](worker_threads.html#workerterminate). When the environment is being torn down, the\nregistered `napi_finalize` callbacks of JavaScript objects, thread-safe\nfunctions and environment instance data are invoked immediately and\nindependently.\n\nThe invocation of `napi_finalize` callbacks is scheduled after the manually\nregistered cleanup hooks. In order to ensure a proper order of addon\nfinalization during environment shutdown to avoid use-after-free in the\n`napi_finalize` callback, addons should register a cleanup hook with\n`napi_add_env_cleanup_hook` and `napi_add_async_cleanup_hook` to manually\nrelease the allocated resource in a proper order.","summary":"The Node.js environment may be torn down at an arbitrary time as soon as possible with JavaScript execution disallowed, like on the request of `worker.terminate()`. When the environment is being torn down, the registered `napi_finalize` callbacks of JavaScript objects, thread-safe functions and environment instance data are invoked immediately and independently.","examples":[],"children":[]}]},{"kind":"section","id":"module-registration","name":"Module registration","title":"Module registration","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"Node-API modules are registered in a manner similar to other modules\nexcept that instead of using the `NODE_MODULE` macro the following\nis used:\n\n```c\nNAPI_MODULE(NODE_GYP_MODULE_NAME, Init)\n```\n\nThe next difference is the signature for the `Init` method. For a Node-API\nmodule it is as follows:\n\n```c\nnapi_value Init(napi_env env, napi_value exports);\n```\n\nThe return value from `Init` is treated as the `exports` object for the module.\nThe `Init` method is passed an empty object via the `exports` parameter as a\nconvenience. If `Init` returns `NULL`, the parameter passed as `exports` is\nexported by the module. Node-API modules cannot modify the `module` object but\ncan specify anything as the `exports` property of the module.\n\nTo add the method `hello` as a function so that it can be called as a method\nprovided by the addon:\n\n```c\nnapi_value Init(napi_env env, napi_value exports) {\n  napi_status status;\n  napi_property_descriptor desc = {\n    \"hello\",\n    NULL,\n    Method,\n    NULL,\n    NULL,\n    NULL,\n    napi_writable | napi_enumerable | napi_configurable,\n    NULL\n  };\n  status = napi_define_properties(env, exports, 1, &desc);\n  if (status != napi_ok) return NULL;\n  return exports;\n}\n```\n\nTo set a function to be returned by the `require()` for the addon:\n\n```c\nnapi_value Init(napi_env env, napi_value exports) {\n  napi_value method;\n  napi_status status;\n  status = napi_create_function(env, \"exports\", NAPI_AUTO_LENGTH, Method, NULL, &method);\n  if (status != napi_ok) return NULL;\n  return method;\n}\n```\n\nTo define a class so that new instances can be created (often used with\n[Object wrap](#object-wrap)):\n\n```c\n// NOTE: partial example, not all referenced code is included\nnapi_value Init(napi_env env, napi_value exports) {\n  napi_status status;\n  napi_property_descriptor properties[] = {\n    { \"value\", NULL, NULL, GetValue, SetValue, NULL, napi_writable | napi_configurable, NULL },\n    DECLARE_NAPI_METHOD(\"plusOne\", PlusOne),\n    DECLARE_NAPI_METHOD(\"multiply\", Multiply),\n  };\n\n  napi_value cons;\n  status =\n      napi_define_class(env, \"MyObject\", New, NULL, 3, properties, &cons);\n  if (status != napi_ok) return NULL;\n\n  status = napi_create_reference(env, cons, 1, &constructor);\n  if (status != napi_ok) return NULL;\n\n  status = napi_set_named_property(env, exports, \"MyObject\", cons);\n  if (status != napi_ok) return NULL;\n\n  return exports;\n}\n```\n\nYou can also use the `NAPI_MODULE_INIT` macro, which acts as a shorthand\nfor `NAPI_MODULE` and defining an `Init` function:\n\n```c\nNAPI_MODULE_INIT(/* napi_env env, napi_value exports */) {\n  napi_value answer;\n  napi_status result;\n\n  status = napi_create_int64(env, 42, &answer);\n  if (status != napi_ok) return NULL;\n\n  status = napi_set_named_property(env, exports, \"answer\", answer);\n  if (status != napi_ok) return NULL;\n\n  return exports;\n}\n```\n\nThe parameters `env` and `exports` are provided to the body of the\n`NAPI_MODULE_INIT` macro.\n\nAll Node-API addons are context-aware, meaning they may be loaded multiple\ntimes. There are a few design considerations when declaring such a module.\nThe documentation on [context-aware addons](addons.html#context-aware-addons) provides more details.\n\nThe variables `env` and `exports` will be available inside the function body\nfollowing the macro invocation.\n\nFor more details on setting properties on objects, see the section on\n[Working with JavaScript properties](#working-with-javascript-properties).\n\nFor more details on building addon modules in general, refer to the existing\nAPI.","summary":"Node-API modules are registered in a manner similar to other modules except that instead of using the `NODE_MODULE` macro the following is used:","examples":[{"language":"c","displayName":null,"code":"NAPI_MODULE(NODE_GYP_MODULE_NAME, Init)"},{"language":"c","displayName":null,"code":"napi_value Init(napi_env env, napi_value exports);"},{"language":"c","displayName":null,"code":"napi_value Init(napi_env env, napi_value exports) {\n  napi_status status;\n  napi_property_descriptor desc = {\n    \"hello\",\n    NULL,\n    Method,\n    NULL,\n    NULL,\n    NULL,\n    napi_writable | napi_enumerable | napi_configurable,\n    NULL\n  };\n  status = napi_define_properties(env, exports, 1, &desc);\n  if (status != napi_ok) return NULL;\n  return exports;\n}"},{"language":"c","displayName":null,"code":"napi_value Init(napi_env env, napi_value exports) {\n  napi_value method;\n  napi_status status;\n  status = napi_create_function(env, \"exports\", NAPI_AUTO_LENGTH, Method, NULL, &method);\n  if (status != napi_ok) return NULL;\n  return method;\n}"},{"language":"c","displayName":null,"code":"// NOTE: partial example, not all referenced code is included\nnapi_value Init(napi_env env, napi_value exports) {\n  napi_status status;\n  napi_property_descriptor properties[] = {\n    { \"value\", NULL, NULL, GetValue, SetValue, NULL, napi_writable | napi_configurable, NULL },\n    DECLARE_NAPI_METHOD(\"plusOne\", PlusOne),\n    DECLARE_NAPI_METHOD(\"multiply\", Multiply),\n  };\n\n  napi_value cons;\n  status =\n      napi_define_class(env, \"MyObject\", New, NULL, 3, properties, &cons);\n  if (status != napi_ok) return NULL;\n\n  status = napi_create_reference(env, cons, 1, &constructor);\n  if (status != napi_ok) return NULL;\n\n  status = napi_set_named_property(env, exports, \"MyObject\", cons);\n  if (status != napi_ok) return NULL;\n\n  return exports;\n}"},{"language":"c","displayName":null,"code":"NAPI_MODULE_INIT(/* napi_env env, napi_value exports */) {\n  napi_value answer;\n  napi_status result;\n\n  status = napi_create_int64(env, 42, &answer);\n  if (status != napi_ok) return NULL;\n\n  status = napi_set_named_property(env, exports, \"answer\", answer);\n  if (status != napi_ok) return NULL;\n\n  return exports;\n}"}],"children":[]},{"kind":"section","id":"working-with-javascript-values","name":"Working with JavaScript values","title":"Working with JavaScript values","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"Node-API exposes a set of APIs to create all types of JavaScript values.\nSome of these types are documented under [Section language types](https://tc39.es/ecma262/#sec-ecmascript-data-types-and-values)\nof the [ECMAScript Language Specification](https://tc39.es/ecma262/).\n\nFundamentally, these APIs are used to do one of the following:\n\n1. Create a new JavaScript object\n2. Convert from a primitive C type to a Node-API value\n3. Convert from Node-API value to a primitive C type\n4. Get global instances including `undefined` and `null`\n\nNode-API values are represented by the type `napi_value`.\nAny Node-API call that requires a JavaScript value takes in a `napi_value`.\nIn some cases, the API does check the type of the `napi_value` up-front.\nHowever, for better performance, it's better for the caller to make sure that\nthe `napi_value` in question is of the JavaScript type expected by the API.","summary":"Node-API exposes a set of APIs to create all types of JavaScript values. Some of these types are documented under Section language types of the ECMAScript Language Specification.","examples":[],"children":[{"kind":"section","id":"enum-types","name":"Enum types","title":"Enum types","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"","summary":"","examples":[],"children":[{"kind":"section","id":"napi_key_collection_mode","name":"napi_key_collection_mode","title":"`napi_key_collection_mode`","scope":"module","overloadOf":null,"stability":null,"added":["v13.7.0","v12.17.0","v10.20.0"],"deprecated":[],"removed":[],"napiVersion":[6],"changes":[],"description":"```c\ntypedef enum {\n  napi_key_include_prototypes,\n  napi_key_own_only\n} napi_key_collection_mode;\n```\n\nDescribes the `Keys/Properties` filter enums:\n\n`napi_key_collection_mode` limits the range of collected properties.\n\n`napi_key_own_only` limits the collected properties to the given\nobject only. `napi_key_include_prototypes` will include all keys\nof the objects's prototype chain as well.","summary":"Describes the `Keys/Properties` filter enums:","examples":[{"language":"c","displayName":null,"code":"typedef enum {\n  napi_key_include_prototypes,\n  napi_key_own_only\n} napi_key_collection_mode;"}],"children":[]},{"kind":"section","id":"napi_key_filter","name":"napi_key_filter","title":"`napi_key_filter`","scope":"module","overloadOf":null,"stability":null,"added":["v13.7.0","v12.17.0","v10.20.0"],"deprecated":[],"removed":[],"napiVersion":[6],"changes":[],"description":"```c\ntypedef enum {\n  napi_key_all_properties = 0,\n  napi_key_writable = 1,\n  napi_key_enumerable = 1 << 1,\n  napi_key_configurable = 1 << 2,\n  napi_key_skip_strings = 1 << 3,\n  napi_key_skip_symbols = 1 << 4\n} napi_key_filter;\n```\n\nProperty filter bit flag. This works with bit operators to build a composite filter.","summary":"Property filter bit flag. This works with bit operators to build a composite filter.","examples":[{"language":"c","displayName":null,"code":"typedef enum {\n  napi_key_all_properties = 0,\n  napi_key_writable = 1,\n  napi_key_enumerable = 1 << 1,\n  napi_key_configurable = 1 << 2,\n  napi_key_skip_strings = 1 << 3,\n  napi_key_skip_symbols = 1 << 4\n} napi_key_filter;"}],"children":[]},{"kind":"section","id":"napi_key_conversion","name":"napi_key_conversion","title":"`napi_key_conversion`","scope":"module","overloadOf":null,"stability":null,"added":["v13.7.0","v12.17.0","v10.20.0"],"deprecated":[],"removed":[],"napiVersion":[6],"changes":[],"description":"```c\ntypedef enum {\n  napi_key_keep_numbers,\n  napi_key_numbers_to_strings\n} napi_key_conversion;\n```\n\n`napi_key_numbers_to_strings` will convert integer indexes to\nstrings. `napi_key_keep_numbers` will return numbers for integer\nindexes.","summary":"`napi_key_numbers_to_strings` will convert integer indexes to strings. `napi_key_keep_numbers` will return numbers for integer indexes.","examples":[{"language":"c","displayName":null,"code":"typedef enum {\n  napi_key_keep_numbers,\n  napi_key_numbers_to_strings\n} napi_key_conversion;"}],"children":[]},{"kind":"section","id":"napi_valuetype","name":"napi_valuetype","title":"`napi_valuetype`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"```c\ntypedef enum {\n  // ES6 types (corresponds to typeof)\n  napi_undefined,\n  napi_null,\n  napi_boolean,\n  napi_number,\n  napi_string,\n  napi_symbol,\n  napi_object,\n  napi_function,\n  napi_external,\n  napi_bigint,\n} napi_valuetype;\n```\n\nDescribes the type of a `napi_value`. This generally corresponds to the types\ndescribed in [Section language types](https://tc39.es/ecma262/#sec-ecmascript-data-types-and-values) of the ECMAScript Language Specification.\nIn addition to types in that section, `napi_valuetype` can also represent\n`Function`s and `Object`s with external data.\n\nA JavaScript value of type `napi_external` appears in JavaScript as a plain\nobject such that no properties can be set on it, and no prototype.","summary":"Describes the type of a `napi_value`. This generally corresponds to the types described in Section language types of the ECMAScript Language Specification. In addition to types in that section, `napi_valuetype` can also represent `Function`s and `Object`s with external data.","examples":[{"language":"c","displayName":null,"code":"typedef enum {\n  // ES6 types (corresponds to typeof)\n  napi_undefined,\n  napi_null,\n  napi_boolean,\n  napi_number,\n  napi_string,\n  napi_symbol,\n  napi_object,\n  napi_function,\n  napi_external,\n  napi_bigint,\n} napi_valuetype;"}],"children":[]},{"kind":"section","id":"napi_typedarray_type","name":"napi_typedarray_type","title":"`napi_typedarray_type`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v25.5.0","v24.13.1"],"prUrl":"https://github.com/nodejs/node/pull/58879","commit":null,"description":"Added `napi_float16_array` for Float16Array support."}],"description":"```c\ntypedef enum {\n  napi_int8_array,\n  napi_uint8_array,\n  napi_uint8_clamped_array,\n  napi_int16_array,\n  napi_uint16_array,\n  napi_int32_array,\n  napi_uint32_array,\n  napi_float32_array,\n  napi_float64_array,\n  napi_bigint64_array,\n  napi_biguint64_array,\n  napi_float16_array,\n} napi_typedarray_type;\n```\n\nThis represents the underlying binary scalar datatype of the `TypedArray`.\nElements of this enum correspond to\n[Section TypedArray objects](https://tc39.es/ecma262/#sec-typedarray-objects) of the [ECMAScript Language Specification](https://tc39.es/ecma262/).","summary":"This represents the underlying binary scalar datatype of the `TypedArray`. Elements of this enum correspond to Section TypedArray objects of the ECMAScript Language Specification.","examples":[{"language":"c","displayName":null,"code":"typedef enum {\n  napi_int8_array,\n  napi_uint8_array,\n  napi_uint8_clamped_array,\n  napi_int16_array,\n  napi_uint16_array,\n  napi_int32_array,\n  napi_uint32_array,\n  napi_float32_array,\n  napi_float64_array,\n  napi_bigint64_array,\n  napi_biguint64_array,\n  napi_float16_array,\n} napi_typedarray_type;"}],"children":[]}]},{"kind":"section","id":"object-creation-functions","name":"Object creation functions","title":"Object creation functions","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"","summary":"","examples":[],"children":[{"kind":"section","id":"napi_create_array","name":"napi_create_array","title":"`napi_create_array`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_create_array(napi_env env, napi_value* result)\n```\n\n* `[in] env`: The environment that the Node-API call is invoked under.\n* `[out] result`: A `napi_value` representing a JavaScript `Array`.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API returns a Node-API value corresponding to a JavaScript `Array` type.\nJavaScript arrays are described in\n[Section Array objects](https://tc39.es/ecma262/#sec-array-objects) of the ECMAScript Language Specification.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_create_array(napi_env env, napi_value* result)"}],"children":[]},{"kind":"section","id":"napi_create_array_with_length","name":"napi_create_array_with_length","title":"`napi_create_array_with_length`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_create_array_with_length(napi_env env,\n                                          size_t length,\n                                          napi_value* result)\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] length`: The initial length of the `Array`.\n* `[out] result`: A `napi_value` representing a JavaScript `Array`.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API returns a Node-API value corresponding to a JavaScript `Array` type.\nThe `Array`'s length property is set to the passed-in length parameter.\nHowever, the underlying buffer is not guaranteed to be pre-allocated by the VM\nwhen the array is created. That behavior is left to the underlying VM\nimplementation. If the buffer must be a contiguous block of memory that can be\ndirectly read and/or written via C, consider using\n[`napi_create_external_arraybuffer`](#napi_create_external_arraybuffer).\n\nJavaScript arrays are described in\n[Section Array objects](https://tc39.es/ecma262/#sec-array-objects) of the ECMAScript Language Specification.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_create_array_with_length(napi_env env,\n                                          size_t length,\n                                          napi_value* result)"}],"children":[]},{"kind":"section","id":"napi_create_arraybuffer","name":"napi_create_arraybuffer","title":"`napi_create_arraybuffer`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_create_arraybuffer(napi_env env,\n                                    size_t byte_length,\n                                    void** data,\n                                    napi_value* result)\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] length`: The length in bytes of the array buffer to create.\n* `[out] data`: Pointer to the underlying byte buffer of the `ArrayBuffer`.\n  `data` can optionally be ignored by passing `NULL`.\n* `[out] result`: A `napi_value` representing a JavaScript `ArrayBuffer`.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API returns a Node-API value corresponding to a JavaScript `ArrayBuffer`.\n`ArrayBuffer`s are used to represent fixed-length binary data buffers. They are\nnormally used as a backing-buffer for `TypedArray` objects.\nThe `ArrayBuffer` allocated will have an underlying byte buffer whose size is\ndetermined by the `length` parameter that's passed in.\nThe underlying buffer is optionally returned back to the caller in case the\ncaller wants to directly manipulate the buffer. This buffer can only be\nwritten to directly from native code. To write to this buffer from JavaScript,\na typed array or `DataView` object would need to be created.\n\nJavaScript `ArrayBuffer` objects are described in\n[Section ArrayBuffer objects](https://tc39.es/ecma262/#sec-arraybuffer-objects) of the ECMAScript Language Specification.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_create_arraybuffer(napi_env env,\n                                    size_t byte_length,\n                                    void** data,\n                                    napi_value* result)"}],"children":[]},{"kind":"section","id":"napi_create_buffer","name":"napi_create_buffer","title":"`napi_create_buffer`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_create_buffer(napi_env env,\n                               size_t size,\n                               void** data,\n                               napi_value* result)\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] size`: Size in bytes of the underlying buffer.\n* `[out] data`: Raw pointer to the underlying buffer.\n  `data` can optionally be ignored by passing `NULL`.\n* `[out] result`: A `napi_value` representing a `node::Buffer`.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API allocates a `node::Buffer` object. While this is still a\nfully-supported data structure, in most cases using a `TypedArray` will suffice.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_create_buffer(napi_env env,\n                               size_t size,\n                               void** data,\n                               napi_value* result)"}],"children":[]},{"kind":"section","id":"napi_create_buffer_copy","name":"napi_create_buffer_copy","title":"`napi_create_buffer_copy`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_create_buffer_copy(napi_env env,\n                                    size_t length,\n                                    const void* data,\n                                    void** result_data,\n                                    napi_value* result)\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] size`: Size in bytes of the input buffer (should be the same as the size\n  of the new buffer).\n* `[in] data`: Raw pointer to the underlying buffer to copy from.\n* `[out] result_data`: Pointer to the new `Buffer`'s underlying data buffer.\n  `result_data` can optionally be ignored by passing `NULL`.\n* `[out] result`: A `napi_value` representing a `node::Buffer`.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API allocates a `node::Buffer` object and initializes it with data copied\nfrom the passed-in buffer. While this is still a fully-supported data\nstructure, in most cases using a `TypedArray` will suffice.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_create_buffer_copy(napi_env env,\n                                    size_t length,\n                                    const void* data,\n                                    void** result_data,\n                                    napi_value* result)"}],"children":[]},{"kind":"section","id":"napi_create_date","name":"napi_create_date","title":"`napi_create_date`","scope":"module","overloadOf":null,"stability":null,"added":["v11.11.0","v10.17.0"],"deprecated":[],"removed":[],"napiVersion":[5],"changes":[],"description":"```c\nnapi_status napi_create_date(napi_env env,\n                             double time,\n                             napi_value* result);\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] time`: ECMAScript time value in milliseconds since 01 January, 1970 UTC.\n* `[out] result`: A `napi_value` representing a JavaScript `Date`.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API does not observe leap seconds; they are ignored, as\nECMAScript aligns with POSIX time specification.\n\nThis API allocates a JavaScript `Date` object.\n\nJavaScript `Date` objects are described in\n[Section Date objects](https://tc39.es/ecma262/#sec-date-objects) of the ECMAScript Language Specification.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_create_date(napi_env env,\n                             double time,\n                             napi_value* result);"}],"children":[]},{"kind":"section","id":"napi_create_external","name":"napi_create_external","title":"`napi_create_external`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_create_external(napi_env env,\n                                 void* data,\n                                 napi_finalize finalize_cb,\n                                 void* finalize_hint,\n                                 napi_value* result)\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] data`: Raw pointer to the external data.\n* `[in] finalize_cb`: Optional callback to call when the external value is being\n  collected. [`napi_finalize`](#napi_finalize) provides more details.\n* `[in] finalize_hint`: Optional hint to pass to the finalize callback during\n  collection.\n* `[out] result`: A `napi_value` representing an external value.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API allocates a JavaScript value with external data attached to it. This\nis used to pass external data through JavaScript code, so it can be retrieved\nlater by native code using [`napi_get_value_external`](#napi_get_value_external).\n\nThe API adds a `napi_finalize` callback which will be called when the JavaScript\nobject just created has been garbage collected.\n\nThe created value is not an object, and therefore does not support additional\nproperties. It is considered a distinct value type: calling `napi_typeof()` with\nan external value yields `napi_external`.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_create_external(napi_env env,\n                                 void* data,\n                                 napi_finalize finalize_cb,\n                                 void* finalize_hint,\n                                 napi_value* result)"}],"children":[]},{"kind":"section","id":"napi_create_external_arraybuffer","name":"napi_create_external_arraybuffer","title":"`napi_create_external_arraybuffer`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status\nnapi_create_external_arraybuffer(napi_env env,\n                                 void* external_data,\n                                 size_t byte_length,\n                                 napi_finalize finalize_cb,\n                                 void* finalize_hint,\n                                 napi_value* result)\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] external_data`: Pointer to the underlying byte buffer of the\n  `ArrayBuffer`.\n* `[in] byte_length`: The length in bytes of the underlying buffer.\n* `[in] finalize_cb`: Optional callback to call when the `ArrayBuffer` is being\n  collected. [`napi_finalize`](#napi_finalize) provides more details.\n* `[in] finalize_hint`: Optional hint to pass to the finalize callback during\n  collection.\n* `[out] result`: A `napi_value` representing a JavaScript `ArrayBuffer`.\n\nReturns `napi_ok` if the API succeeded.\n\n**Some runtimes other than Node.js have dropped support for external buffers**.\nOn runtimes other than Node.js this method may return\n`napi_no_external_buffers_allowed` to indicate that external\nbuffers are not supported. One such runtime is Electron as\ndescribed in this issue\n[electron/issues/35801](https://github.com/electron/electron/issues/35801).\n\nIn order to maintain broadest compatibility with all runtimes\nyou may define `NODE_API_NO_EXTERNAL_BUFFERS_ALLOWED` in your addon before\nincludes for the node-api headers. Doing so will hide the 2 functions\nthat create external buffers. This will ensure a compilation error\noccurs if you accidentally use one of these methods.\n\nThis API returns a Node-API value corresponding to a JavaScript `ArrayBuffer`.\nThe underlying byte buffer of the `ArrayBuffer` is externally allocated and\nmanaged. The caller must ensure that the byte buffer remains valid until the\nfinalize callback is called.\n\nThe API adds a `napi_finalize` callback which will be called when the JavaScript\nobject just created has been garbage collected.\n\nJavaScript `ArrayBuffer`s are described in\n[Section ArrayBuffer objects](https://tc39.es/ecma262/#sec-arraybuffer-objects) of the ECMAScript Language Specification.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status\nnapi_create_external_arraybuffer(napi_env env,\n                                 void* external_data,\n                                 size_t byte_length,\n                                 napi_finalize finalize_cb,\n                                 void* finalize_hint,\n                                 napi_value* result)"}],"children":[]},{"kind":"section","id":"node_api_create_external_sharedarraybuffer","name":"node_api_create_external_sharedarraybuffer","title":"`node_api_create_external_sharedarraybuffer`","scope":"module","overloadOf":null,"stability":null,"added":["v26.1.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"```c\nnapi_status\nnode_api_create_external_sharedarraybuffer(napi_env env,\n                                           void* external_data,\n                                           size_t byte_length,\n                                           node_api_noenv_finalize finalize_cb,\n                                           void* finalize_hint,\n                                           napi_value* result)\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] external_data`: Pointer to the underlying byte buffer of the\n  `SharedArrayBuffer`.\n* `[in] byte_length`: The length in bytes of the underlying buffer.\n* `[in] finalize_cb`: Optional callback to call when the `SharedArrayBuffer` is\n  being collected. Called on an arbitrary thread. Because a `SharedArrayBuffer`\n  can outlive the environment it's created in, the callback does not receive a\n  reference to `env`.\n* `[in] finalize_hint`: Optional hint to pass to the finalize callback during\n  collection.\n* `[out] result`: A `napi_value` representing a JavaScript `SharedArrayBuffer`.\n\nReturns `napi_ok` if the API succeeded.\n\nCreate a `SharedArrayBuffer` with externally managed memory.\n\nSee the entry on [`napi_create_external_arraybuffer`](#napi_create_external_arraybuffer) for runtime\ncompatibility.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status\nnode_api_create_external_sharedarraybuffer(napi_env env,\n                                           void* external_data,\n                                           size_t byte_length,\n                                           node_api_noenv_finalize finalize_cb,\n                                           void* finalize_hint,\n                                           napi_value* result)"}],"children":[]},{"kind":"section","id":"napi_create_external_buffer","name":"napi_create_external_buffer","title":"`napi_create_external_buffer`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_create_external_buffer(napi_env env,\n                                        size_t length,\n                                        void* data,\n                                        napi_finalize finalize_cb,\n                                        void* finalize_hint,\n                                        napi_value* result)\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] length`: Size in bytes of the input buffer (should be the same as the\n  size of the new buffer).\n* `[in] data`: Raw pointer to the underlying buffer to expose to JavaScript.\n* `[in] finalize_cb`: Optional callback to call when the `ArrayBuffer` is being\n  collected. [`napi_finalize`](#napi_finalize) provides more details.\n* `[in] finalize_hint`: Optional hint to pass to the finalize callback during\n  collection.\n* `[out] result`: A `napi_value` representing a `node::Buffer`.\n\nReturns `napi_ok` if the API succeeded.\n\n**Some runtimes other than Node.js have dropped support for external buffers**.\nOn runtimes other than Node.js this method may return\n`napi_no_external_buffers_allowed` to indicate that external\nbuffers are not supported. One such runtime is Electron as\ndescribed in this issue\n[electron/issues/35801](https://github.com/electron/electron/issues/35801).\n\nIn order to maintain broadest compatibility with all runtimes\nyou may define `NODE_API_NO_EXTERNAL_BUFFERS_ALLOWED` in your addon before\nincludes for the node-api headers. Doing so will hide the 2 functions\nthat create external buffers. This will ensure a compilation error\noccurs if you accidentally use one of these methods.\n\nThis API allocates a `node::Buffer` object and initializes it with data\nbacked by the passed in buffer. While this is still a fully-supported data\nstructure, in most cases using a `TypedArray` will suffice.\n\nThe API adds a `napi_finalize` callback which will be called when the JavaScript\nobject just created has been garbage collected.\n\nFor Node.js >=4 `Buffers` are `Uint8Array`s.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_create_external_buffer(napi_env env,\n                                        size_t length,\n                                        void* data,\n                                        napi_finalize finalize_cb,\n                                        void* finalize_hint,\n                                        napi_value* result)"}],"children":[]},{"kind":"section","id":"napi_create_object","name":"napi_create_object","title":"`napi_create_object`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_create_object(napi_env env, napi_value* result)\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[out] result`: A `napi_value` representing a JavaScript `Object`.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API allocates a default JavaScript `Object`.\nIt is the equivalent of doing `new Object()` in JavaScript.\n\nThe JavaScript `Object` type is described in [Section object type](https://tc39.es/ecma262/#sec-object-type) of the\nECMAScript Language Specification.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_create_object(napi_env env, napi_value* result)"}],"children":[]},{"kind":"section","id":"node_api_create_object_with_properties","name":"node_api_create_object_with_properties","title":"`node_api_create_object_with_properties`","scope":"module","overloadOf":null,"stability":{"index":"1","description":"Experimental"},"added":["v25.2.0","v24.12.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"```cpp\nnapi_status node_api_create_object_with_properties(napi_env env,\n                                                   napi_value prototype_or_null,\n                                                   const napi_value* property_names,\n                                                   const napi_value* property_values,\n                                                   size_t property_count,\n                                                   napi_value* result)\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] prototype_or_null`: The prototype object for the new object. Can be a\n  `napi_value` representing a JavaScript object to use as the prototype, a\n  `napi_value` representing JavaScript `null`, or a `nullptr` that will be converted to `null`.\n* `[in] property_names`: Array of `napi_value` representing the property names.\n* `[in] property_values`: Array of `napi_value` representing the property values.\n* `[in] property_count`: Number of properties in the arrays.\n* `[out] result`: A `napi_value` representing a JavaScript `Object`.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API creates a JavaScript `Object` with the specified prototype and\nproperties. This is more efficient than calling `napi_create_object` followed\nby multiple `napi_set_property` calls, as it can create the object with all\nproperties atomically, avoiding potential V8 map transitions.\n\nThe arrays `property_names` and `property_values` must have the same length\nspecified by `property_count`. The properties are added to the object in the\norder they appear in the arrays.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"cpp","displayName":null,"code":"napi_status node_api_create_object_with_properties(napi_env env,\n                                                   napi_value prototype_or_null,\n                                                   const napi_value* property_names,\n                                                   const napi_value* property_values,\n                                                   size_t property_count,\n                                                   napi_value* result)"}],"children":[]},{"kind":"section","id":"napi_create_symbol","name":"napi_create_symbol","title":"`napi_create_symbol`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_create_symbol(napi_env env,\n                               napi_value description,\n                               napi_value* result)\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] description`: Optional `napi_value` which refers to a JavaScript\n  `string` to be set as the description for the symbol.\n* `[out] result`: A `napi_value` representing a JavaScript `symbol`.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API creates a JavaScript `symbol` value from a UTF8-encoded C string.\n\nThe JavaScript `symbol` type is described in [Section symbol type](https://tc39.es/ecma262/#sec-ecmascript-language-types-symbol-type)\nof the ECMAScript Language Specification.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_create_symbol(napi_env env,\n                               napi_value description,\n                               napi_value* result)"}],"children":[]},{"kind":"section","id":"node_api_symbol_for","name":"node_api_symbol_for","title":"`node_api_symbol_for`","scope":"module","overloadOf":null,"stability":null,"added":["v17.5.0","v16.15.0"],"deprecated":[],"removed":[],"napiVersion":[9],"changes":[],"description":"```c\nnapi_status node_api_symbol_for(napi_env env,\n                                const char* utf8description,\n                                size_t length,\n                                napi_value* result)\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] utf8description`: UTF-8 C string representing the text to be used as the\n  description for the symbol.\n* `[in] length`: The length of the description string in bytes, or\n  `NAPI_AUTO_LENGTH` if it is null-terminated.\n* `[out] result`: A `napi_value` representing a JavaScript `symbol`.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API searches in the global registry for an existing symbol with the given\ndescription. If the symbol already exists it will be returned, otherwise a new\nsymbol will be created in the registry.\n\nThe JavaScript `symbol` type is described in [Section symbol type](https://tc39.es/ecma262/#sec-ecmascript-language-types-symbol-type) of the ECMAScript\nLanguage Specification.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status node_api_symbol_for(napi_env env,\n                                const char* utf8description,\n                                size_t length,\n                                napi_value* result)"}],"children":[]},{"kind":"section","id":"napi_create_typedarray","name":"napi_create_typedarray","title":"`napi_create_typedarray`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[{"versions":["v26.2.0"],"prUrl":"https://github.com/nodejs/node/pull/62710","commit":null,"description":"Added support for `SharedArrayBuffer`."}],"description":"```c\nnapi_status napi_create_typedarray(napi_env env,\n                                   napi_typedarray_type type,\n                                   size_t length,\n                                   napi_value arraybuffer,\n                                   size_t byte_offset,\n                                   napi_value* result)\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] type`: Scalar datatype of the elements within the `TypedArray`.\n* `[in] length`: Number of elements in the `TypedArray`.\n* `[in] arraybuffer`: `ArrayBuffer` or `SharedArrayBuffer` underlying the\n  typed array.\n* `[in] byte_offset`: The byte offset within the `ArrayBuffer` or\n  `SharedArrayBuffer` from which to start projecting the `TypedArray`.\n* `[out] result`: A `napi_value` representing a JavaScript `TypedArray`.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API creates a JavaScript `TypedArray` object over an existing\n`ArrayBuffer` or `SharedArrayBuffer`. `TypedArray` objects provide an\narray-like view over an underlying data buffer where each element has the same\nunderlying binary scalar datatype.\n\nIt is required that `(length * size_of_element) + byte_offset` is less than or\nequal to the size in bytes of the `ArrayBuffer` or `SharedArrayBuffer` passed\nin. If not, a `RangeError` exception is raised.\n\nFor element sizes greater than 1, `byte_offset` is required to be a multiple\nof the element size. If not, a `RangeError` exception is raised.\n\nJavaScript `TypedArray` objects are described in\n[Section TypedArray objects](https://tc39.es/ecma262/#sec-typedarray-objects) of the ECMAScript Language Specification.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_create_typedarray(napi_env env,\n                                   napi_typedarray_type type,\n                                   size_t length,\n                                   napi_value arraybuffer,\n                                   size_t byte_offset,\n                                   napi_value* result)"}],"children":[]},{"kind":"section","id":"node_api_create_buffer_from_arraybuffer","name":"node_api_create_buffer_from_arraybuffer","title":"`node_api_create_buffer_from_arraybuffer`","scope":"module","overloadOf":null,"stability":null,"added":["v23.0.0","v22.12.0"],"deprecated":[],"removed":[],"napiVersion":[10],"changes":[],"description":"```c\nnapi_status NAPI_CDECL node_api_create_buffer_from_arraybuffer(napi_env env,\n                                                              napi_value arraybuffer,\n                                                              size_t byte_offset,\n                                                              size_t byte_length,\n                                                              napi_value* result)\n```\n\n* **`[in] env`**: The environment that the API is invoked under.\n* **`[in] arraybuffer`**: The `ArrayBuffer` from which the buffer will be created.\n* **`[in] byte_offset`**: The byte offset within the `ArrayBuffer` from which to start creating the buffer.\n* **`[in] byte_length`**: The length in bytes of the buffer to be created from the `ArrayBuffer`.\n* **`[out] result`**: A `napi_value` representing the created JavaScript `Buffer` object.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API creates a JavaScript `Buffer` object from an existing `ArrayBuffer`.\nThe `Buffer` object is a Node.js-specific class that provides a way to work with binary data directly in JavaScript.\n\nThe byte range `[byte_offset, byte_offset + byte_length)`\nmust be within the bounds of the `ArrayBuffer`. If `byte_offset + byte_length`\nexceeds the size of the `ArrayBuffer`, a `RangeError` exception is raised.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status NAPI_CDECL node_api_create_buffer_from_arraybuffer(napi_env env,\n                                                              napi_value arraybuffer,\n                                                              size_t byte_offset,\n                                                              size_t byte_length,\n                                                              napi_value* result)"}],"children":[]},{"kind":"section","id":"napi_create_dataview","name":"napi_create_dataview","title":"`napi_create_dataview`","scope":"module","overloadOf":null,"stability":null,"added":["v8.3.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[{"versions":["v25.5.0","v24.13.1"],"prUrl":"https://github.com/nodejs/node/pull/60473","commit":null,"description":"Added support for `SharedArrayBuffer`."}],"description":"```c\nnapi_status napi_create_dataview(napi_env env,\n                                 size_t byte_length,\n                                 napi_value arraybuffer,\n                                 size_t byte_offset,\n                                 napi_value* result)\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] length`: Number of elements in the `DataView`.\n* `[in] arraybuffer`: `ArrayBuffer` or `SharedArrayBuffer` underlying the\n  `DataView`.\n* `[in] byte_offset`: The byte offset within the `ArrayBuffer` from which to\n  start projecting the `DataView`.\n* `[out] result`: A `napi_value` representing a JavaScript `DataView`.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API creates a JavaScript `DataView` object over an existing `ArrayBuffer`\nor `SharedArrayBuffer`. `DataView` objects provide an array-like view over an\nunderlying data buffer, but one which allows items of different size and type in\nthe `ArrayBuffer` or `SharedArrayBuffer`.\n\nIt is required that `byte_length + byte_offset` is less than or equal to the\nsize in bytes of the array passed in. If not, a `RangeError` exception is\nraised.\n\nJavaScript `DataView` objects are described in\n[Section DataView objects](https://tc39.es/ecma262/#sec-dataview-objects) of the ECMAScript Language Specification.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_create_dataview(napi_env env,\n                                 size_t byte_length,\n                                 napi_value arraybuffer,\n                                 size_t byte_offset,\n                                 napi_value* result)"}],"children":[]}]},{"kind":"section","id":"functions-to-convert-from-c-types-to-node-api","name":"Functions to convert from C types to Node-API","title":"Functions to convert from C types to Node-API","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"","summary":"","examples":[],"children":[{"kind":"section","id":"napi_create_int32","name":"napi_create_int32","title":"`napi_create_int32`","scope":"module","overloadOf":null,"stability":null,"added":["v8.4.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_create_int32(napi_env env, int32_t value, napi_value* result)\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] value`: Integer value to be represented in JavaScript.\n* `[out] result`: A `napi_value` representing a JavaScript `number`.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API is used to convert from the C `int32_t` type to the JavaScript\n`number` type.\n\nThe JavaScript `number` type is described in\n[Section number type](https://tc39.es/ecma262/#sec-ecmascript-language-types-number-type) of the ECMAScript Language Specification.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_create_int32(napi_env env, int32_t value, napi_value* result)"}],"children":[]},{"kind":"section","id":"napi_create_uint32","name":"napi_create_uint32","title":"`napi_create_uint32`","scope":"module","overloadOf":null,"stability":null,"added":["v8.4.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_create_uint32(napi_env env, uint32_t value, napi_value* result)\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] value`: Unsigned integer value to be represented in JavaScript.\n* `[out] result`: A `napi_value` representing a JavaScript `number`.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API is used to convert from the C `uint32_t` type to the JavaScript\n`number` type.\n\nThe JavaScript `number` type is described in\n[Section number type](https://tc39.es/ecma262/#sec-ecmascript-language-types-number-type) of the ECMAScript Language Specification.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_create_uint32(napi_env env, uint32_t value, napi_value* result)"}],"children":[]},{"kind":"section","id":"napi_create_int64","name":"napi_create_int64","title":"`napi_create_int64`","scope":"module","overloadOf":null,"stability":null,"added":["v8.4.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_create_int64(napi_env env, int64_t value, napi_value* result)\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] value`: Integer value to be represented in JavaScript.\n* `[out] result`: A `napi_value` representing a JavaScript `number`.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API is used to convert from the C `int64_t` type to the JavaScript\n`number` type.\n\nThe JavaScript `number` type is described in [Section number type](https://tc39.es/ecma262/#sec-ecmascript-language-types-number-type)\nof the ECMAScript Language Specification. Note the complete range of `int64_t`\ncannot be represented with full precision in JavaScript. Integer values\noutside the range of [`Number.MIN_SAFE_INTEGER`](https://tc39.es/ecma262/#sec-number.min_safe_integer) `-(2**53 - 1)` -\n[`Number.MAX_SAFE_INTEGER`](https://tc39.es/ecma262/#sec-number.max_safe_integer) `(2**53 - 1)` will lose precision.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_create_int64(napi_env env, int64_t value, napi_value* result)"}],"children":[]},{"kind":"section","id":"napi_create_double","name":"napi_create_double","title":"`napi_create_double`","scope":"module","overloadOf":null,"stability":null,"added":["v8.4.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_create_double(napi_env env, double value, napi_value* result)\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] value`: Double-precision value to be represented in JavaScript.\n* `[out] result`: A `napi_value` representing a JavaScript `number`.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API is used to convert from the C `double` type to the JavaScript\n`number` type.\n\nThe JavaScript `number` type is described in\n[Section number type](https://tc39.es/ecma262/#sec-ecmascript-language-types-number-type) of the ECMAScript Language Specification.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_create_double(napi_env env, double value, napi_value* result)"}],"children":[]},{"kind":"section","id":"napi_create_bigint_int64","name":"napi_create_bigint_int64","title":"`napi_create_bigint_int64`","scope":"module","overloadOf":null,"stability":null,"added":["v10.7.0"],"deprecated":[],"removed":[],"napiVersion":[6],"changes":[],"description":"```c\nnapi_status napi_create_bigint_int64(napi_env env,\n                                     int64_t value,\n                                     napi_value* result);\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] value`: Integer value to be represented in JavaScript.\n* `[out] result`: A `napi_value` representing a JavaScript `BigInt`.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API converts the C `int64_t` type to the JavaScript `BigInt` type.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_create_bigint_int64(napi_env env,\n                                     int64_t value,\n                                     napi_value* result);"}],"children":[]},{"kind":"section","id":"napi_create_bigint_uint64","name":"napi_create_bigint_uint64","title":"`napi_create_bigint_uint64`","scope":"module","overloadOf":null,"stability":null,"added":["v10.7.0"],"deprecated":[],"removed":[],"napiVersion":[6],"changes":[],"description":"```c\nnapi_status napi_create_bigint_uint64(napi_env env,\n                                      uint64_t value,\n                                      napi_value* result);\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] value`: Unsigned integer value to be represented in JavaScript.\n* `[out] result`: A `napi_value` representing a JavaScript `BigInt`.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API converts the C `uint64_t` type to the JavaScript `BigInt` type.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_create_bigint_uint64(napi_env env,\n                                      uint64_t value,\n                                      napi_value* result);"}],"children":[]},{"kind":"section","id":"napi_create_bigint_words","name":"napi_create_bigint_words","title":"`napi_create_bigint_words`","scope":"module","overloadOf":null,"stability":null,"added":["v10.7.0"],"deprecated":[],"removed":[],"napiVersion":[6],"changes":[],"description":"```c\nnapi_status napi_create_bigint_words(napi_env env,\n                                     int sign_bit,\n                                     size_t word_count,\n                                     const uint64_t* words,\n                                     napi_value* result);\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] sign_bit`: Determines if the resulting `BigInt` will be positive or\n  negative.\n* `[in] word_count`: The length of the `words` array.\n* `[in] words`: An array of `uint64_t` little-endian 64-bit words.\n* `[out] result`: A `napi_value` representing a JavaScript `BigInt`.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API converts an array of unsigned 64-bit words into a single `BigInt`\nvalue.\n\nThe resulting `BigInt` is calculated as: (–1)<sup>`sign_bit`</sup> (`words[0]`\n× (2<sup>64</sup>)<sup>0</sup> + `words[1]` × (2<sup>64</sup>)<sup>1</sup> + …)","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_create_bigint_words(napi_env env,\n                                     int sign_bit,\n                                     size_t word_count,\n                                     const uint64_t* words,\n                                     napi_value* result);"}],"children":[]},{"kind":"section","id":"napi_create_string_latin1","name":"napi_create_string_latin1","title":"`napi_create_string_latin1`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_create_string_latin1(napi_env env,\n                                      const char* str,\n                                      size_t length,\n                                      napi_value* result);\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] str`: Character buffer representing an ISO-8859-1-encoded string.\n* `[in] length`: The length of the string in bytes, or `NAPI_AUTO_LENGTH` if it\n  is null-terminated.\n* `[out] result`: A `napi_value` representing a JavaScript `string`.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API creates a JavaScript `string` value from an ISO-8859-1-encoded C\nstring. The native string is copied.\n\nThe JavaScript `string` type is described in\n[Section string type](https://tc39.es/ecma262/#sec-ecmascript-language-types-string-type) of the ECMAScript Language Specification.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_create_string_latin1(napi_env env,\n                                      const char* str,\n                                      size_t length,\n                                      napi_value* result);"}],"children":[]},{"kind":"section","id":"node_api_create_external_string_latin1","name":"node_api_create_external_string_latin1","title":"`node_api_create_external_string_latin1`","scope":"module","overloadOf":null,"stability":null,"added":["v20.4.0","v18.18.0"],"deprecated":[],"removed":[],"napiVersion":[10],"changes":[],"description":"```c\nnapi_status\nnode_api_create_external_string_latin1(napi_env env,\n                                       char* str,\n                                       size_t length,\n                                       napi_finalize finalize_callback,\n                                       void* finalize_hint,\n                                       napi_value* result,\n                                       bool* copied);\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] str`: Character buffer representing an ISO-8859-1-encoded string.\n* `[in] length`: The length of the string in bytes, or `NAPI_AUTO_LENGTH` if it\n  is null-terminated.\n* `[in] finalize_callback`: The function to call when the string is being\n  collected. The function will be called with the following parameters:\n  * `[in] env`: The environment in which the add-on is running. This value\n    may be null if the string is being collected as part of the termination\n    of the worker or the main Node.js instance.\n  * `[in] data`: This is the value `str` as a `void*` pointer.\n  * `[in] finalize_hint`: This is the value `finalize_hint` that was given\n    to the API.\n    [`napi_finalize`](#napi_finalize) provides more details.\n    This parameter is optional. Passing a null value means that the add-on\n    doesn't need to be notified when the corresponding JavaScript string is\n    collected.\n* `[in] finalize_hint`: Optional hint to pass to the finalize callback during\n  collection.\n* `[out] result`: A `napi_value` representing a JavaScript `string`.\n* `[out] copied`: Whether the string was copied. If it was, the finalizer will\n  already have been invoked to destroy `str`.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API creates a JavaScript `string` value from an ISO-8859-1-encoded C\nstring. The native string may not be copied and must thus exist for the entire\nlife cycle of the JavaScript value.\n\nThe JavaScript `string` type is described in\n[Section string type](https://tc39.es/ecma262/#sec-ecmascript-language-types-string-type) of the ECMAScript Language Specification.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status\nnode_api_create_external_string_latin1(napi_env env,\n                                       char* str,\n                                       size_t length,\n                                       napi_finalize finalize_callback,\n                                       void* finalize_hint,\n                                       napi_value* result,\n                                       bool* copied);"}],"children":[]},{"kind":"section","id":"napi_create_string_utf16","name":"napi_create_string_utf16","title":"`napi_create_string_utf16`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_create_string_utf16(napi_env env,\n                                     const char16_t* str,\n                                     size_t length,\n                                     napi_value* result)\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] str`: Character buffer representing a UTF16-LE-encoded string.\n* `[in] length`: The length of the string in two-byte code units, or\n  `NAPI_AUTO_LENGTH` if it is null-terminated.\n* `[out] result`: A `napi_value` representing a JavaScript `string`.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API creates a JavaScript `string` value from a UTF16-LE-encoded C string.\nThe native string is copied.\n\nThe JavaScript `string` type is described in\n[Section string type](https://tc39.es/ecma262/#sec-ecmascript-language-types-string-type) of the ECMAScript Language Specification.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_create_string_utf16(napi_env env,\n                                     const char16_t* str,\n                                     size_t length,\n                                     napi_value* result)"}],"children":[]},{"kind":"section","id":"node_api_create_external_string_utf16","name":"node_api_create_external_string_utf16","title":"`node_api_create_external_string_utf16`","scope":"module","overloadOf":null,"stability":null,"added":["v20.4.0","v18.18.0"],"deprecated":[],"removed":[],"napiVersion":[10],"changes":[],"description":"```c\nnapi_status\nnode_api_create_external_string_utf16(napi_env env,\n                                      char16_t* str,\n                                      size_t length,\n                                      napi_finalize finalize_callback,\n                                      void* finalize_hint,\n                                      napi_value* result,\n                                      bool* copied);\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] str`: Character buffer representing a UTF16-LE-encoded string.\n* `[in] length`: The length of the string in two-byte code units, or\n  `NAPI_AUTO_LENGTH` if it is null-terminated.\n* `[in] finalize_callback`: The function to call when the string is being\n  collected. The function will be called with the following parameters:\n  * `[in] env`: The environment in which the add-on is running. This value\n    may be null if the string is being collected as part of the termination\n    of the worker or the main Node.js instance.\n  * `[in] data`: This is the value `str` as a `void*` pointer.\n  * `[in] finalize_hint`: This is the value `finalize_hint` that was given\n    to the API.\n    [`napi_finalize`](#napi_finalize) provides more details.\n    This parameter is optional. Passing a null value means that the add-on\n    doesn't need to be notified when the corresponding JavaScript string is\n    collected.\n* `[in] finalize_hint`: Optional hint to pass to the finalize callback during\n  collection.\n* `[out] result`: A `napi_value` representing a JavaScript `string`.\n* `[out] copied`: Whether the string was copied. If it was, the finalizer will\n  already have been invoked to destroy `str`.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API creates a JavaScript `string` value from a UTF16-LE-encoded C string.\nThe native string may not be copied and must thus exist for the entire life\ncycle of the JavaScript value.\n\nThe JavaScript `string` type is described in\n[Section string type](https://tc39.es/ecma262/#sec-ecmascript-language-types-string-type) of the ECMAScript Language Specification.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status\nnode_api_create_external_string_utf16(napi_env env,\n                                      char16_t* str,\n                                      size_t length,\n                                      napi_finalize finalize_callback,\n                                      void* finalize_hint,\n                                      napi_value* result,\n                                      bool* copied);"}],"children":[]},{"kind":"section","id":"napi_create_string_utf8","name":"napi_create_string_utf8","title":"`napi_create_string_utf8`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_create_string_utf8(napi_env env,\n                                    const char* str,\n                                    size_t length,\n                                    napi_value* result)\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] str`: Character buffer representing a UTF8-encoded string.\n* `[in] length`: The length of the string in bytes, or `NAPI_AUTO_LENGTH` if it\n  is null-terminated.\n* `[out] result`: A `napi_value` representing a JavaScript `string`.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API creates a JavaScript `string` value from a UTF8-encoded C string.\nThe native string is copied.\n\nThe JavaScript `string` type is described in\n[Section string type](https://tc39.es/ecma262/#sec-ecmascript-language-types-string-type) of the ECMAScript Language Specification.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_create_string_utf8(napi_env env,\n                                    const char* str,\n                                    size_t length,\n                                    napi_value* result)"}],"children":[]}]},{"kind":"section","id":"functions-to-create-optimized-property-keys","name":"Functions to create optimized property keys","title":"Functions to create optimized property keys","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"Many JavaScript engines including V8 use internalized strings as keys\nto set and get property values. They typically use a hash table to create\nand lookup such strings. While it adds some cost per key creation, it improves\nthe performance after that by enabling comparison of string pointers instead\nof the whole strings.\n\nIf a new JavaScript string is intended to be used as a property key, then for\nsome JavaScript engines it will be more efficient to use the functions in this\nsection. Otherwise, use the `napi_create_string_utf8` or\n`node_api_create_external_string_utf8` series functions as there may be\nadditional overhead in creating/storing strings with the property key\ncreation methods.","summary":"Many JavaScript engines including V8 use internalized strings as keys to set and get property values. They typically use a hash table to create and lookup such strings. While it adds some cost per key creation, it improves the performance after that by enabling comparison of string pointers instead of the whole strings.","examples":[],"children":[{"kind":"section","id":"node_api_create_property_key_latin1","name":"node_api_create_property_key_latin1","title":"`node_api_create_property_key_latin1`","scope":"module","overloadOf":null,"stability":null,"added":["v22.9.0","v20.18.0"],"deprecated":[],"removed":[],"napiVersion":[10],"changes":[],"description":"```c\nnapi_status NAPI_CDECL node_api_create_property_key_latin1(napi_env env,\n                                                           const char* str,\n                                                           size_t length,\n                                                           napi_value* result);\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] str`: Character buffer representing an ISO-8859-1-encoded string.\n* `[in] length`: The length of the string in bytes, or `NAPI_AUTO_LENGTH` if it\n  is null-terminated.\n* `[out] result`: A `napi_value` representing an optimized JavaScript `string`\n  to be used as a property key for objects.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API creates an optimized JavaScript `string` value from\nan ISO-8859-1-encoded C string to be used as a property key for objects.\nThe native string is copied. In contrast with `napi_create_string_latin1`,\nsubsequent calls to this function with the same `str` pointer may benefit from a speedup\nin the creation of the requested `napi_value`, depending on the engine.\n\nThe JavaScript `string` type is described in\n[Section string type](https://tc39.es/ecma262/#sec-ecmascript-language-types-string-type) of the ECMAScript Language Specification.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status NAPI_CDECL node_api_create_property_key_latin1(napi_env env,\n                                                           const char* str,\n                                                           size_t length,\n                                                           napi_value* result);"}],"children":[]},{"kind":"section","id":"node_api_create_property_key_utf16","name":"node_api_create_property_key_utf16","title":"`node_api_create_property_key_utf16`","scope":"module","overloadOf":null,"stability":null,"added":["v21.7.0","v20.12.0"],"deprecated":[],"removed":[],"napiVersion":[10],"changes":[],"description":"```c\nnapi_status NAPI_CDECL node_api_create_property_key_utf16(napi_env env,\n                                                          const char16_t* str,\n                                                          size_t length,\n                                                          napi_value* result);\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] str`: Character buffer representing a UTF16-LE-encoded string.\n* `[in] length`: The length of the string in two-byte code units, or\n  `NAPI_AUTO_LENGTH` if it is null-terminated.\n* `[out] result`: A `napi_value` representing an optimized JavaScript `string`\n  to be used as a property key for objects.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API creates an optimized JavaScript `string` value from\na UTF16-LE-encoded C string to be used as a property key for objects.\nThe native string is copied.\n\nThe JavaScript `string` type is described in\n[Section string type](https://tc39.es/ecma262/#sec-ecmascript-language-types-string-type) of the ECMAScript Language Specification.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status NAPI_CDECL node_api_create_property_key_utf16(napi_env env,\n                                                          const char16_t* str,\n                                                          size_t length,\n                                                          napi_value* result);"}],"children":[]},{"kind":"section","id":"node_api_create_property_key_utf8","name":"node_api_create_property_key_utf8","title":"`node_api_create_property_key_utf8`","scope":"module","overloadOf":null,"stability":null,"added":["v22.9.0","v20.18.0"],"deprecated":[],"removed":[],"napiVersion":[10],"changes":[],"description":"```c\nnapi_status NAPI_CDECL node_api_create_property_key_utf8(napi_env env,\n                                                         const char* str,\n                                                         size_t length,\n                                                         napi_value* result);\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] str`: Character buffer representing a UTF8-encoded string.\n* `[in] length`: The length of the string in two-byte code units, or\n  `NAPI_AUTO_LENGTH` if it is null-terminated.\n* `[out] result`: A `napi_value` representing an optimized JavaScript `string`\n  to be used as a property key for objects.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API creates an optimized JavaScript `string` value from\na UTF8-encoded C string to be used as a property key for objects.\nThe native string is copied.\n\nThe JavaScript `string` type is described in\n[Section string type](https://tc39.es/ecma262/#sec-ecmascript-language-types-string-type) of the ECMAScript Language Specification.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status NAPI_CDECL node_api_create_property_key_utf8(napi_env env,\n                                                         const char* str,\n                                                         size_t length,\n                                                         napi_value* result);"}],"children":[]}]},{"kind":"section","id":"functions-to-convert-from-node-api-to-c-types","name":"Functions to convert from Node-API to C types","title":"Functions to convert from Node-API to C types","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"","summary":"","examples":[],"children":[{"kind":"section","id":"napi_get_array_length","name":"napi_get_array_length","title":"`napi_get_array_length`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_get_array_length(napi_env env,\n                                  napi_value value,\n                                  uint32_t* result)\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] value`: `napi_value` representing the JavaScript `Array` whose length is\n  being queried.\n* `[out] result`: `uint32` representing length of the array.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API returns the length of an array.\n\n`Array` length is described in [Section Array instance length](https://tc39.es/ecma262/#sec-properties-of-array-instances-length) of the ECMAScript Language\nSpecification.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_get_array_length(napi_env env,\n                                  napi_value value,\n                                  uint32_t* result)"}],"children":[]},{"kind":"section","id":"napi_get_arraybuffer_info","name":"napi_get_arraybuffer_info","title":"`napi_get_arraybuffer_info`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[{"versions":["v24.9.0","v22.21.0"],"prUrl":"https://github.com/nodejs/node/pull/59071","commit":null,"description":"Added support for `SharedArrayBuffer`."}],"description":"```c\nnapi_status napi_get_arraybuffer_info(napi_env env,\n                                      napi_value arraybuffer,\n                                      void** data,\n                                      size_t* byte_length)\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] arraybuffer`: `napi_value` representing the `ArrayBuffer` or `SharedArrayBuffer` being queried.\n* `[out] data`: The underlying data buffer of the `ArrayBuffer` or `SharedArrayBuffer`\n  is `0`, this may be `NULL` or any other pointer value.\n* `[out] byte_length`: Length in bytes of the underlying data buffer.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API is used to retrieve the underlying data buffer of an `ArrayBuffer` or `SharedArrayBuffer` and its length.\n\n*WARNING*: Use caution while using this API. The lifetime of the underlying data\nbuffer is managed by the `ArrayBuffer` or `SharedArrayBuffer` even after it's returned. A\npossible safe way to use this API is in conjunction with\n[`napi_create_reference`](#napi_create_reference), which can be used to guarantee control over the\nlifetime of the `ArrayBuffer` or `SharedArrayBuffer`. It's also safe to use the returned data buffer\nwithin the same callback as long as there are no calls to other APIs that might\ntrigger a GC.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_get_arraybuffer_info(napi_env env,\n                                      napi_value arraybuffer,\n                                      void** data,\n                                      size_t* byte_length)"}],"children":[]},{"kind":"section","id":"napi_get_buffer_info","name":"napi_get_buffer_info","title":"`napi_get_buffer_info`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_get_buffer_info(napi_env env,\n                                 napi_value value,\n                                 void** data,\n                                 size_t* length)\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] value`: `napi_value` representing the `node::Buffer` or `Uint8Array`\n  being queried.\n* `[out] data`: The underlying data buffer of the `node::Buffer` or\n  `Uint8Array`. If length is `0`, this may be `NULL` or any other pointer value.\n* `[out] length`: Length in bytes of the underlying data buffer.\n\nReturns `napi_ok` if the API succeeded.\n\nThis method returns the identical `data` and `byte_length` as\n[`napi_get_typedarray_info`](#napi_get_typedarray_info). And `napi_get_typedarray_info` accepts a\n`node::Buffer` (a Uint8Array) as the value too.\n\nThis API is used to retrieve the underlying data buffer of a `node::Buffer`\nand its length.\n\n*Warning*: Use caution while using this API since the underlying data buffer's\nlifetime is not guaranteed if it's managed by the VM.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_get_buffer_info(napi_env env,\n                                 napi_value value,\n                                 void** data,\n                                 size_t* length)"}],"children":[]},{"kind":"section","id":"napi_get_prototype","name":"napi_get_prototype","title":"`napi_get_prototype`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_get_prototype(napi_env env,\n                               napi_value object,\n                               napi_value* result)\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] object`: `napi_value` representing JavaScript `Object` whose prototype\n  to return. This returns the equivalent of `Object.getPrototypeOf` (which is\n  not the same as the function's `prototype` property).\n* `[out] result`: `napi_value` representing prototype of the given object.\n\nReturns `napi_ok` if the API succeeded.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_get_prototype(napi_env env,\n                               napi_value object,\n                               napi_value* result)"}],"children":[]},{"kind":"section","id":"napi_get_typedarray_info","name":"napi_get_typedarray_info","title":"`napi_get_typedarray_info`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_get_typedarray_info(napi_env env,\n                                     napi_value typedarray,\n                                     napi_typedarray_type* type,\n                                     size_t* length,\n                                     void** data,\n                                     napi_value* arraybuffer,\n                                     size_t* byte_offset)\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] typedarray`: `napi_value` representing the `TypedArray` whose\n  properties to query.\n* `[out] type`: Scalar datatype of the elements within the `TypedArray`.\n* `[out] length`: The number of elements in the `TypedArray`.\n* `[out] data`: The data buffer underlying the `TypedArray` adjusted by\n  the `byte_offset` value so that it points to the first element in the\n  `TypedArray`. If the length of the array is `0`, this may be `NULL` or\n  any other pointer value.\n* `[out] arraybuffer`: The `ArrayBuffer` or `SharedArrayBuffer` underlying the\n  `TypedArray`.\n* `[out] byte_offset`: The byte offset within the underlying native array\n  at which the first element of the arrays is located. The value for the data\n  parameter has already been adjusted so that data points to the first element\n  in the array. Therefore, the first byte of the native array would be at\n  `data - byte_offset`.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API returns various properties of a typed array.\n\nAny of the out parameters may be `NULL` if that property is unneeded.\n\n*Warning*: Use caution while using this API since the underlying data buffer\nis managed by the VM.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_get_typedarray_info(napi_env env,\n                                     napi_value typedarray,\n                                     napi_typedarray_type* type,\n                                     size_t* length,\n                                     void** data,\n                                     napi_value* arraybuffer,\n                                     size_t* byte_offset)"}],"children":[]},{"kind":"section","id":"napi_get_dataview_info","name":"napi_get_dataview_info","title":"`napi_get_dataview_info`","scope":"module","overloadOf":null,"stability":null,"added":["v8.3.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_get_dataview_info(napi_env env,\n                                   napi_value dataview,\n                                   size_t* byte_length,\n                                   void** data,\n                                   napi_value* arraybuffer,\n                                   size_t* byte_offset)\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] dataview`: `napi_value` representing the `DataView` whose\n  properties to query.\n* `[out] byte_length`: Number of bytes in the `DataView`.\n* `[out] data`: The data buffer underlying the `DataView`.\n  If byte\\_length is `0`, this may be `NULL` or any other pointer value.\n* `[out] arraybuffer`: `ArrayBuffer` underlying the `DataView`.\n* `[out] byte_offset`: The byte offset within the data buffer from which\n  to start projecting the `DataView`.\n\nReturns `napi_ok` if the API succeeded.\n\nAny of the out parameters may be `NULL` if that property is unneeded.\n\nThis API returns various properties of a `DataView`.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_get_dataview_info(napi_env env,\n                                   napi_value dataview,\n                                   size_t* byte_length,\n                                   void** data,\n                                   napi_value* arraybuffer,\n                                   size_t* byte_offset)"}],"children":[]},{"kind":"section","id":"napi_get_date_value","name":"napi_get_date_value","title":"`napi_get_date_value`","scope":"module","overloadOf":null,"stability":null,"added":["v11.11.0","v10.17.0"],"deprecated":[],"removed":[],"napiVersion":[5],"changes":[],"description":"```c\nnapi_status napi_get_date_value(napi_env env,\n                                napi_value value,\n                                double* result)\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] value`: `napi_value` representing a JavaScript `Date`.\n* `[out] result`: Time value as a `double` represented as milliseconds since\n  midnight at the beginning of 01 January, 1970 UTC.\n\nThis API does not observe leap seconds; they are ignored, as\nECMAScript aligns with POSIX time specification.\n\nReturns `napi_ok` if the API succeeded. If a non-date `napi_value` is passed\nin it returns `napi_date_expected`.\n\nThis API returns the C double primitive of time value for the given JavaScript\n`Date`.","summary":"This API does not observe leap seconds; they are ignored, as ECMAScript aligns with POSIX time specification.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_get_date_value(napi_env env,\n                                napi_value value,\n                                double* result)"}],"children":[]},{"kind":"section","id":"napi_get_value_bool","name":"napi_get_value_bool","title":"`napi_get_value_bool`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_get_value_bool(napi_env env, napi_value value, bool* result)\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] value`: `napi_value` representing JavaScript `Boolean`.\n* `[out] result`: C boolean primitive equivalent of the given JavaScript\n  `Boolean`.\n\nReturns `napi_ok` if the API succeeded. If a non-boolean `napi_value` is\npassed in it returns `napi_boolean_expected`.\n\nThis API returns the C boolean primitive equivalent of the given JavaScript\n`Boolean`.","summary":"Returns `napi_ok` if the API succeeded. If a non-boolean `napi_value` is passed in it returns `napi_boolean_expected`.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_get_value_bool(napi_env env, napi_value value, bool* result)"}],"children":[]},{"kind":"section","id":"napi_get_value_double","name":"napi_get_value_double","title":"`napi_get_value_double`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_get_value_double(napi_env env,\n                                  napi_value value,\n                                  double* result)\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] value`: `napi_value` representing JavaScript `number`.\n* `[out] result`: C double primitive equivalent of the given JavaScript\n  `number`.\n\nReturns `napi_ok` if the API succeeded. If a non-number `napi_value` is passed\nin it returns `napi_number_expected`.\n\nThis API returns the C double primitive equivalent of the given JavaScript\n`number`.","summary":"Returns `napi_ok` if the API succeeded. If a non-number `napi_value` is passed in it returns `napi_number_expected`.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_get_value_double(napi_env env,\n                                  napi_value value,\n                                  double* result)"}],"children":[]},{"kind":"section","id":"napi_get_value_bigint_int64","name":"napi_get_value_bigint_int64","title":"`napi_get_value_bigint_int64`","scope":"module","overloadOf":null,"stability":null,"added":["v10.7.0"],"deprecated":[],"removed":[],"napiVersion":[6],"changes":[],"description":"```c\nnapi_status napi_get_value_bigint_int64(napi_env env,\n                                        napi_value value,\n                                        int64_t* result,\n                                        bool* lossless);\n```\n\n* `[in] env`: The environment that the API is invoked under\n* `[in] value`: `napi_value` representing JavaScript `BigInt`.\n* `[out] result`: C `int64_t` primitive equivalent of the given JavaScript\n  `BigInt`.\n* `[out] lossless`: Indicates whether the `BigInt` value was converted\n  losslessly.\n\nReturns `napi_ok` if the API succeeded. If a non-`BigInt` is passed in it\nreturns `napi_bigint_expected`.\n\nThis API returns the C `int64_t` primitive equivalent of the given JavaScript\n`BigInt`. If needed it will truncate the value, setting `lossless` to `false`.","summary":"Returns `napi_ok` if the API succeeded. If a non-`BigInt` is passed in it returns `napi_bigint_expected`.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_get_value_bigint_int64(napi_env env,\n                                        napi_value value,\n                                        int64_t* result,\n                                        bool* lossless);"}],"children":[]},{"kind":"section","id":"napi_get_value_bigint_uint64","name":"napi_get_value_bigint_uint64","title":"`napi_get_value_bigint_uint64`","scope":"module","overloadOf":null,"stability":null,"added":["v10.7.0"],"deprecated":[],"removed":[],"napiVersion":[6],"changes":[],"description":"```c\nnapi_status napi_get_value_bigint_uint64(napi_env env,\n                                        napi_value value,\n                                        uint64_t* result,\n                                        bool* lossless);\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] value`: `napi_value` representing JavaScript `BigInt`.\n* `[out] result`: C `uint64_t` primitive equivalent of the given JavaScript\n  `BigInt`.\n* `[out] lossless`: Indicates whether the `BigInt` value was converted\n  losslessly.\n\nReturns `napi_ok` if the API succeeded. If a non-`BigInt` is passed in it\nreturns `napi_bigint_expected`.\n\nThis API returns the C `uint64_t` primitive equivalent of the given JavaScript\n`BigInt`. If needed it will truncate the value, setting `lossless` to `false`.","summary":"Returns `napi_ok` if the API succeeded. If a non-`BigInt` is passed in it returns `napi_bigint_expected`.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_get_value_bigint_uint64(napi_env env,\n                                        napi_value value,\n                                        uint64_t* result,\n                                        bool* lossless);"}],"children":[]},{"kind":"section","id":"napi_get_value_bigint_words","name":"napi_get_value_bigint_words","title":"`napi_get_value_bigint_words`","scope":"module","overloadOf":null,"stability":null,"added":["v10.7.0"],"deprecated":[],"removed":[],"napiVersion":[6],"changes":[],"description":"```c\nnapi_status napi_get_value_bigint_words(napi_env env,\n                                        napi_value value,\n                                        int* sign_bit,\n                                        size_t* word_count,\n                                        uint64_t* words);\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] value`: `napi_value` representing JavaScript `BigInt`.\n* `[out] sign_bit`: Integer representing if the JavaScript `BigInt` is positive\n  or negative.\n* `[in/out] word_count`: Must be initialized to the length of the `words`\n  array. Upon return, it will be set to the actual number of words that\n  would be needed to store this `BigInt`.\n* `[out] words`: Pointer to a pre-allocated 64-bit word array.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API converts a single `BigInt` value into a sign bit, 64-bit little-endian\narray, and the number of elements in the array. `sign_bit` and `words` may be\nboth set to `NULL`, in order to get only `word_count`.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_get_value_bigint_words(napi_env env,\n                                        napi_value value,\n                                        int* sign_bit,\n                                        size_t* word_count,\n                                        uint64_t* words);"}],"children":[]},{"kind":"section","id":"napi_get_value_external","name":"napi_get_value_external","title":"`napi_get_value_external`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_get_value_external(napi_env env,\n                                    napi_value value,\n                                    void** result)\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] value`: `napi_value` representing JavaScript external value.\n* `[out] result`: Pointer to the data wrapped by the JavaScript external value.\n\nReturns `napi_ok` if the API succeeded. If a non-external `napi_value` is\npassed in it returns `napi_invalid_arg`.\n\nThis API retrieves the external data pointer that was previously passed to\n`napi_create_external()`.","summary":"Returns `napi_ok` if the API succeeded. If a non-external `napi_value` is passed in it returns `napi_invalid_arg`.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_get_value_external(napi_env env,\n                                    napi_value value,\n                                    void** result)"}],"children":[]},{"kind":"section","id":"napi_get_value_int32","name":"napi_get_value_int32","title":"`napi_get_value_int32`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_get_value_int32(napi_env env,\n                                 napi_value value,\n                                 int32_t* result)\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] value`: `napi_value` representing JavaScript `number`.\n* `[out] result`: C `int32` primitive equivalent of the given JavaScript\n  `number`.\n\nReturns `napi_ok` if the API succeeded. If a non-number `napi_value`\nis passed in `napi_number_expected`.\n\nThis API returns the C `int32` primitive equivalent\nof the given JavaScript `number`.\n\nIf the number exceeds the range of the 32 bit integer, then the result is\ntruncated to the equivalent of the bottom 32 bits. This can result in a large\npositive number becoming a negative number if the value is > 2<sup>31</sup> - 1.\n\nNon-finite number values (`NaN`, `+Infinity`, or `-Infinity`) set the\nresult to zero.","summary":"Returns `napi_ok` if the API succeeded. If a non-number `napi_value` is passed in `napi_number_expected`.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_get_value_int32(napi_env env,\n                                 napi_value value,\n                                 int32_t* result)"}],"children":[]},{"kind":"section","id":"napi_get_value_int64","name":"napi_get_value_int64","title":"`napi_get_value_int64`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_get_value_int64(napi_env env,\n                                 napi_value value,\n                                 int64_t* result)\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] value`: `napi_value` representing JavaScript `number`.\n* `[out] result`: C `int64` primitive equivalent of the given JavaScript\n  `number`.\n\nReturns `napi_ok` if the API succeeded. If a non-number `napi_value`\nis passed in it returns `napi_number_expected`.\n\nThis API returns the C `int64` primitive equivalent of the given JavaScript\n`number`.\n\n`number` values outside the range of [`Number.MIN_SAFE_INTEGER`](https://tc39.es/ecma262/#sec-number.min_safe_integer)\n`-(2**53 - 1)` - [`Number.MAX_SAFE_INTEGER`](https://tc39.es/ecma262/#sec-number.max_safe_integer) `(2**53 - 1)` will lose\nprecision.\n\nNon-finite number values (`NaN`, `+Infinity`, or `-Infinity`) set the\nresult to zero.","summary":"Returns `napi_ok` if the API succeeded. If a non-number `napi_value` is passed in it returns `napi_number_expected`.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_get_value_int64(napi_env env,\n                                 napi_value value,\n                                 int64_t* result)"}],"children":[]},{"kind":"section","id":"napi_get_value_string_latin1","name":"napi_get_value_string_latin1","title":"`napi_get_value_string_latin1`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_get_value_string_latin1(napi_env env,\n                                         napi_value value,\n                                         char* buf,\n                                         size_t bufsize,\n                                         size_t* result)\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] value`: `napi_value` representing JavaScript string.\n* `[in] buf`: Buffer to write the ISO-8859-1-encoded string into. If `NULL` is\n  passed in, the length of the string in bytes and excluding the null terminator\n  is returned in `result`.\n* `[in] bufsize`: Size of the destination buffer. When this value is\n  insufficient, the returned string is truncated and null-terminated.\n  If this value is zero, then the string is not returned and no changes are done\n  to the buffer.\n* `[out] result`: Number of bytes copied into the buffer, excluding the null\n  terminator.\n\nReturns `napi_ok` if the API succeeded. If a non-`string` `napi_value`\nis passed in it returns `napi_string_expected`.\n\nThis API returns the ISO-8859-1-encoded string corresponding the value passed\nin.","summary":"Returns `napi_ok` if the API succeeded. If a non-`string` `napi_value` is passed in it returns `napi_string_expected`.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_get_value_string_latin1(napi_env env,\n                                         napi_value value,\n                                         char* buf,\n                                         size_t bufsize,\n                                         size_t* result)"}],"children":[]},{"kind":"section","id":"napi_get_value_string_utf8","name":"napi_get_value_string_utf8","title":"`napi_get_value_string_utf8`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_get_value_string_utf8(napi_env env,\n                                       napi_value value,\n                                       char* buf,\n                                       size_t bufsize,\n                                       size_t* result)\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] value`: `napi_value` representing JavaScript string.\n* `[in] buf`: Buffer to write the UTF8-encoded string into. If `NULL` is passed\n  in, the length of the string in bytes and excluding the null terminator is\n  returned in `result`.\n* `[in] bufsize`: Size of the destination buffer. When this value is\n  insufficient, the returned string is truncated and null-terminated.\n  If this value is zero, then the string is not returned and no changes are done\n  to the buffer.\n* `[out] result`: Number of bytes copied into the buffer, excluding the null\n  terminator.\n\nReturns `napi_ok` if the API succeeded. If a non-`string` `napi_value`\nis passed in it returns `napi_string_expected`.\n\nThis API returns the UTF8-encoded string corresponding the value passed in.","summary":"Returns `napi_ok` if the API succeeded. If a non-`string` `napi_value` is passed in it returns `napi_string_expected`.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_get_value_string_utf8(napi_env env,\n                                       napi_value value,\n                                       char* buf,\n                                       size_t bufsize,\n                                       size_t* result)"}],"children":[]},{"kind":"section","id":"napi_get_value_string_utf16","name":"napi_get_value_string_utf16","title":"`napi_get_value_string_utf16`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_get_value_string_utf16(napi_env env,\n                                        napi_value value,\n                                        char16_t* buf,\n                                        size_t bufsize,\n                                        size_t* result)\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] value`: `napi_value` representing JavaScript string.\n* `[in] buf`: Buffer to write the UTF16-LE-encoded string into. If `NULL` is\n  passed in, the length of the string in 2-byte code units and excluding the\n  null terminator is returned.\n* `[in] bufsize`: Size of the destination buffer. When this value is\n  insufficient, the returned string is truncated and null-terminated.\n  If this value is zero, then the string is not returned and no changes are done\n  to the buffer.\n* `[out] result`: Number of 2-byte code units copied into the buffer, excluding\n  the null terminator.\n\nReturns `napi_ok` if the API succeeded. If a non-`string` `napi_value`\nis passed in it returns `napi_string_expected`.\n\nThis API returns the UTF16-encoded string corresponding the value passed in.","summary":"Returns `napi_ok` if the API succeeded. If a non-`string` `napi_value` is passed in it returns `napi_string_expected`.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_get_value_string_utf16(napi_env env,\n                                        napi_value value,\n                                        char16_t* buf,\n                                        size_t bufsize,\n                                        size_t* result)"}],"children":[]},{"kind":"section","id":"napi_get_value_uint32","name":"napi_get_value_uint32","title":"`napi_get_value_uint32`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_get_value_uint32(napi_env env,\n                                  napi_value value,\n                                  uint32_t* result)\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] value`: `napi_value` representing JavaScript `number`.\n* `[out] result`: C primitive equivalent of the given `napi_value` as a\n  `uint32_t`.\n\nReturns `napi_ok` if the API succeeded. If a non-number `napi_value`\nis passed in it returns `napi_number_expected`.\n\nThis API returns the C primitive equivalent of the given `napi_value` as a\n`uint32_t`.","summary":"Returns `napi_ok` if the API succeeded. If a non-number `napi_value` is passed in it returns `napi_number_expected`.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_get_value_uint32(napi_env env,\n                                  napi_value value,\n                                  uint32_t* result)"}],"children":[]}]},{"kind":"section","id":"functions-to-get-global-instances","name":"Functions to get global instances","title":"Functions to get global instances","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"","summary":"","examples":[],"children":[{"kind":"section","id":"napi_get_boolean","name":"napi_get_boolean","title":"`napi_get_boolean`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_get_boolean(napi_env env, bool value, napi_value* result)\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] value`: The value of the boolean to retrieve.\n* `[out] result`: `napi_value` representing JavaScript `Boolean` singleton to\n  retrieve.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API is used to return the JavaScript singleton object that is used to\nrepresent the given boolean value.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_get_boolean(napi_env env, bool value, napi_value* result)"}],"children":[]},{"kind":"section","id":"napi_get_global","name":"napi_get_global","title":"`napi_get_global`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_get_global(napi_env env, napi_value* result)\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[out] result`: `napi_value` representing JavaScript `global` object.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API returns the `global` object.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_get_global(napi_env env, napi_value* result)"}],"children":[]},{"kind":"section","id":"napi_get_null","name":"napi_get_null","title":"`napi_get_null`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_get_null(napi_env env, napi_value* result)\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[out] result`: `napi_value` representing JavaScript `null` object.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API returns the `null` object.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_get_null(napi_env env, napi_value* result)"}],"children":[]},{"kind":"section","id":"napi_get_undefined","name":"napi_get_undefined","title":"`napi_get_undefined`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_get_undefined(napi_env env, napi_value* result)\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[out] result`: `napi_value` representing JavaScript Undefined value.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API returns the Undefined object.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_get_undefined(napi_env env, napi_value* result)"}],"children":[]}]}]},{"kind":"section","id":"working-with-javascript-values-and-abstract-operations","name":"Working with JavaScript values and abstract operations","title":"Working with JavaScript values and abstract operations","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"Node-API exposes a set of APIs to perform some abstract operations on JavaScript\nvalues.\n\nThese APIs support doing one of the following:\n\n1. Coerce JavaScript values to specific JavaScript types (such as `number` or\n   `string`).\n2. Check the type of a JavaScript value.\n3. Check for equality between two JavaScript values.","summary":"Node-API exposes a set of APIs to perform some abstract operations on JavaScript values.","examples":[],"children":[{"kind":"section","id":"napi_coerce_to_bool","name":"napi_coerce_to_bool","title":"`napi_coerce_to_bool`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_coerce_to_bool(napi_env env,\n                                napi_value value,\n                                napi_value* result)\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] value`: The JavaScript value to coerce.\n* `[out] result`: `napi_value` representing the coerced JavaScript `Boolean`.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API implements the abstract operation `ToBoolean()` as defined in\n[Section ToBoolean](https://tc39.es/ecma262/#sec-toboolean) of the ECMAScript Language Specification.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_coerce_to_bool(napi_env env,\n                                napi_value value,\n                                napi_value* result)"}],"children":[]},{"kind":"section","id":"napi_coerce_to_number","name":"napi_coerce_to_number","title":"`napi_coerce_to_number`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_coerce_to_number(napi_env env,\n                                  napi_value value,\n                                  napi_value* result)\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] value`: The JavaScript value to coerce.\n* `[out] result`: `napi_value` representing the coerced JavaScript `number`.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API implements the abstract operation `ToNumber()` as defined in\n[Section ToNumber](https://tc39.es/ecma262/#sec-tonumber) of the ECMAScript Language Specification.\nThis function potentially runs JS code if the passed-in value is an\nobject.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_coerce_to_number(napi_env env,\n                                  napi_value value,\n                                  napi_value* result)"}],"children":[]},{"kind":"section","id":"napi_coerce_to_object","name":"napi_coerce_to_object","title":"`napi_coerce_to_object`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_coerce_to_object(napi_env env,\n                                  napi_value value,\n                                  napi_value* result)\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] value`: The JavaScript value to coerce.\n* `[out] result`: `napi_value` representing the coerced JavaScript `Object`.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API implements the abstract operation `ToObject()` as defined in\n[Section ToObject](https://tc39.es/ecma262/#sec-toobject) of the ECMAScript Language Specification.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_coerce_to_object(napi_env env,\n                                  napi_value value,\n                                  napi_value* result)"}],"children":[]},{"kind":"section","id":"napi_coerce_to_string","name":"napi_coerce_to_string","title":"`napi_coerce_to_string`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_coerce_to_string(napi_env env,\n                                  napi_value value,\n                                  napi_value* result)\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] value`: The JavaScript value to coerce.\n* `[out] result`: `napi_value` representing the coerced JavaScript `string`.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API implements the abstract operation `ToString()` as defined in\n[Section ToString](https://tc39.es/ecma262/#sec-tostring) of the ECMAScript Language Specification.\nThis function potentially runs JS code if the passed-in value is an\nobject.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_coerce_to_string(napi_env env,\n                                  napi_value value,\n                                  napi_value* result)"}],"children":[]},{"kind":"section","id":"napi_typeof","name":"napi_typeof","title":"`napi_typeof`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_typeof(napi_env env, napi_value value, napi_valuetype* result)\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] value`: The JavaScript value whose type to query.\n* `[out] result`: The type of the JavaScript value.\n\nReturns `napi_ok` if the API succeeded.\n\n* `napi_invalid_arg` if the type of `value` is not a known ECMAScript type and\n  `value` is not an External value.\n\nThis API represents behavior similar to invoking the `typeof` Operator on\nthe object as defined in [Section typeof operator](https://tc39.es/ecma262/#sec-typeof-operator) of the ECMAScript Language\nSpecification. However, there are some differences:\n\n1. It has support for detecting an External value.\n2. It detects `null` as a separate type, while ECMAScript `typeof` would detect\n   `object`.\n\nIf `value` has a type that is invalid, an error is returned.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_typeof(napi_env env, napi_value value, napi_valuetype* result)"}],"children":[]},{"kind":"section","id":"napi_instanceof","name":"napi_instanceof","title":"`napi_instanceof`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_instanceof(napi_env env,\n                            napi_value object,\n                            napi_value constructor,\n                            bool* result)\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] object`: The JavaScript value to check.\n* `[in] constructor`: The JavaScript function object of the constructor function\n  to check against.\n* `[out] result`: Boolean that is set to true if `object instanceof constructor`\n  is true.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API represents invoking the `instanceof` Operator on the object as\ndefined in [Section instanceof operator](https://tc39.es/ecma262/#sec-instanceofoperator) of the ECMAScript Language Specification.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_instanceof(napi_env env,\n                            napi_value object,\n                            napi_value constructor,\n                            bool* result)"}],"children":[]},{"kind":"section","id":"napi_is_array","name":"napi_is_array","title":"`napi_is_array`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_is_array(napi_env env, napi_value value, bool* result)\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] value`: The JavaScript value to check.\n* `[out] result`: Whether the given object is an array.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API represents invoking the `IsArray` operation on the object\nas defined in [Section IsArray](https://tc39.es/ecma262/#sec-isarray) of the ECMAScript Language Specification.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_is_array(napi_env env, napi_value value, bool* result)"}],"children":[]},{"kind":"section","id":"napi_is_arraybuffer","name":"napi_is_arraybuffer","title":"`napi_is_arraybuffer`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_is_arraybuffer(napi_env env, napi_value value, bool* result)\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] value`: The JavaScript value to check.\n* `[out] result`: Whether the given object is an `ArrayBuffer`.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API checks if the `Object` passed in is an array buffer.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_is_arraybuffer(napi_env env, napi_value value, bool* result)"}],"children":[]},{"kind":"section","id":"napi_is_buffer","name":"napi_is_buffer","title":"`napi_is_buffer`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_is_buffer(napi_env env, napi_value value, bool* result)\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] value`: The JavaScript value to check.\n* `[out] result`: Whether the given `napi_value` represents a `node::Buffer` or\n  `Uint8Array` object.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API checks if the `Object` passed in is a buffer or Uint8Array.\n[`napi_is_typedarray`](#napi_is_typedarray) should be preferred if the caller needs to check if the\nvalue is a Uint8Array.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_is_buffer(napi_env env, napi_value value, bool* result)"}],"children":[]},{"kind":"section","id":"napi_is_date","name":"napi_is_date","title":"`napi_is_date`","scope":"module","overloadOf":null,"stability":null,"added":["v11.11.0","v10.17.0"],"deprecated":[],"removed":[],"napiVersion":[5],"changes":[],"description":"```c\nnapi_status napi_is_date(napi_env env, napi_value value, bool* result)\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] value`: The JavaScript value to check.\n* `[out] result`: Whether the given `napi_value` represents a JavaScript `Date`\n  object.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API checks if the `Object` passed in is a date.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_is_date(napi_env env, napi_value value, bool* result)"}],"children":[]},{"kind":"section","id":"napi_is_error-1","name":"napi_is_error","title":"`napi_is_error`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_is_error(napi_env env, napi_value value, bool* result)\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] value`: The JavaScript value to check.\n* `[out] result`: Whether the given `napi_value` represents an `Error` object.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API checks if the `Object` passed in is an `Error`.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_is_error(napi_env env, napi_value value, bool* result)"}],"children":[]},{"kind":"section","id":"napi_is_typedarray","name":"napi_is_typedarray","title":"`napi_is_typedarray`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_is_typedarray(napi_env env, napi_value value, bool* result)\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] value`: The JavaScript value to check.\n* `[out] result`: Whether the given `napi_value` represents a `TypedArray`.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API checks if the `Object` passed in is a typed array.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_is_typedarray(napi_env env, napi_value value, bool* result)"}],"children":[]},{"kind":"section","id":"napi_is_dataview","name":"napi_is_dataview","title":"`napi_is_dataview`","scope":"module","overloadOf":null,"stability":null,"added":["v8.3.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_is_dataview(napi_env env, napi_value value, bool* result)\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] value`: The JavaScript value to check.\n* `[out] result`: Whether the given `napi_value` represents a `DataView`.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API checks if the `Object` passed in is a `DataView`.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_is_dataview(napi_env env, napi_value value, bool* result)"}],"children":[]},{"kind":"section","id":"napi_strict_equals","name":"napi_strict_equals","title":"`napi_strict_equals`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_strict_equals(napi_env env,\n                               napi_value lhs,\n                               napi_value rhs,\n                               bool* result)\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] lhs`: The JavaScript value to check.\n* `[in] rhs`: The JavaScript value to check against.\n* `[out] result`: Whether the two `napi_value` objects are equal.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API represents the invocation of the Strict Equality algorithm as\ndefined in [Section IsStrictlyEqual](https://tc39.es/ecma262/#sec-strict-equality-comparison) of the ECMAScript Language Specification.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_strict_equals(napi_env env,\n                               napi_value lhs,\n                               napi_value rhs,\n                               bool* result)"}],"children":[]},{"kind":"section","id":"napi_detach_arraybuffer","name":"napi_detach_arraybuffer","title":"`napi_detach_arraybuffer`","scope":"module","overloadOf":null,"stability":null,"added":["v13.0.0","v12.16.0","v10.22.0"],"deprecated":[],"removed":[],"napiVersion":[7],"changes":[],"description":"```c\nnapi_status napi_detach_arraybuffer(napi_env env,\n                                    napi_value arraybuffer)\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] arraybuffer`: The JavaScript `ArrayBuffer` to be detached.\n\nReturns `napi_ok` if the API succeeded. If a non-detachable `ArrayBuffer` is\npassed in it returns `napi_detachable_arraybuffer_expected`.\n\nGenerally, an `ArrayBuffer` is non-detachable if it has been detached before.\nThe engine may impose additional conditions on whether an `ArrayBuffer` is\ndetachable. For example, V8 requires that the `ArrayBuffer` be external,\nthat is, created with [`napi_create_external_arraybuffer`](#napi_create_external_arraybuffer).\n\nThis API represents the invocation of the `ArrayBuffer` detach operation as\ndefined in [Section detachArrayBuffer](https://tc39.es/ecma262/#sec-detacharraybuffer) of the ECMAScript Language Specification.","summary":"Returns `napi_ok` if the API succeeded. If a non-detachable `ArrayBuffer` is passed in it returns `napi_detachable_arraybuffer_expected`.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_detach_arraybuffer(napi_env env,\n                                    napi_value arraybuffer)"}],"children":[]},{"kind":"section","id":"napi_is_detached_arraybuffer","name":"napi_is_detached_arraybuffer","title":"`napi_is_detached_arraybuffer`","scope":"module","overloadOf":null,"stability":null,"added":["v13.3.0","v12.16.0","v10.22.0"],"deprecated":[],"removed":[],"napiVersion":[7],"changes":[],"description":"```c\nnapi_status napi_is_detached_arraybuffer(napi_env env,\n                                         napi_value arraybuffer,\n                                         bool* result)\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] arraybuffer`: The JavaScript `ArrayBuffer` to be checked.\n* `[out] result`: Whether the `arraybuffer` is detached.\n\nReturns `napi_ok` if the API succeeded.\n\nThe `ArrayBuffer` is considered detached if its internal data is `null`.\n\nThis API represents the invocation of the `ArrayBuffer` `IsDetachedBuffer`\noperation as defined in [Section isDetachedBuffer](https://tc39.es/ecma262/#sec-isdetachedbuffer) of the ECMAScript Language\nSpecification.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_is_detached_arraybuffer(napi_env env,\n                                         napi_value arraybuffer,\n                                         bool* result)"}],"children":[]},{"kind":"section","id":"node_api_is_sharedarraybuffer","name":"node_api_is_sharedarraybuffer","title":"`node_api_is_sharedarraybuffer`","scope":"module","overloadOf":null,"stability":{"index":"1","description":"Experimental"},"added":["v24.9.0","v22.21.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"```c\nnapi_status node_api_is_sharedarraybuffer(napi_env env, napi_value value, bool* result)\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] value`: The JavaScript value to check.\n* `[out] result`: Whether the given `napi_value` represents a `SharedArrayBuffer`.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API checks if the Object passed in is a `SharedArrayBuffer`.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status node_api_is_sharedarraybuffer(napi_env env, napi_value value, bool* result)"}],"children":[]},{"kind":"section","id":"node_api_create_sharedarraybuffer","name":"node_api_create_sharedarraybuffer","title":"`node_api_create_sharedarraybuffer`","scope":"module","overloadOf":null,"stability":{"index":"1","description":"Experimental"},"added":["v24.9.0","v22.21.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"```c\nnapi_status node_api_create_sharedarraybuffer(napi_env env,\n                                             size_t byte_length,\n                                             void** data,\n                                             napi_value* result)\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] byte_length`: The length in bytes of the shared array buffer to create.\n* `[out] data`: Pointer to the underlying byte buffer of the `SharedArrayBuffer`.\n  `data` can optionally be ignored by passing `NULL`.\n* `[out] result`: A `napi_value` representing a JavaScript `SharedArrayBuffer`.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API returns a Node-API value corresponding to a JavaScript `SharedArrayBuffer`.\n`SharedArrayBuffer`s are used to represent fixed-length binary data buffers that\ncan be shared across multiple workers.\n\nThe `SharedArrayBuffer` allocated will have an underlying byte buffer whose size is\ndetermined by the `byte_length` parameter that's passed in.\nThe underlying buffer is optionally returned back to the caller in case the\ncaller wants to directly manipulate the buffer. This buffer can only be\nwritten to directly from native code. To write to this buffer from JavaScript,\na typed array or `DataView` object would need to be created.\n\nJavaScript `SharedArrayBuffer` objects are described in\n[Section SharedArrayBuffer objects](https://tc39.es/ecma262/#sec-sharedarraybuffer-objects) of the ECMAScript Language Specification.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status node_api_create_sharedarraybuffer(napi_env env,\n                                             size_t byte_length,\n                                             void** data,\n                                             napi_value* result)"}],"children":[]}]},{"kind":"section","id":"working-with-javascript-properties","name":"Working with JavaScript properties","title":"Working with JavaScript properties","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"Node-API exposes a set of APIs to get and set properties on JavaScript\nobjects.\n\nProperties in JavaScript are represented as a tuple of a key and a value.\nFundamentally, all property keys in Node-API can be represented in one of the\nfollowing forms:\n\n* Named: a simple UTF8-encoded string\n* Integer-Indexed: an index value represented by `uint32_t`\n* JavaScript value: these are represented in Node-API by `napi_value`. This can\n  be a `napi_value` representing a `string`, `number`, or `symbol`.\n\nNode-API values are represented by the type `napi_value`.\nAny Node-API call that requires a JavaScript value takes in a `napi_value`.\nHowever, it's the caller's responsibility to make sure that the\n`napi_value` in question is of the JavaScript type expected by the API.\n\nThe APIs documented in this section provide a simple interface to\nget and set properties on arbitrary JavaScript objects represented by\n`napi_value`.\n\nFor instance, consider the following JavaScript code snippet:\n\n```js\nconst obj = {};\nobj.myProp = 123;\n```\n\nThe equivalent can be done using Node-API values with the following snippet:\n\n```c\nnapi_status status = napi_generic_failure;\n\n// const obj = {}\nnapi_value obj, value;\nstatus = napi_create_object(env, &obj);\nif (status != napi_ok) return status;\n\n// Create a napi_value for 123\nstatus = napi_create_int32(env, 123, &value);\nif (status != napi_ok) return status;\n\n// obj.myProp = 123\nstatus = napi_set_named_property(env, obj, \"myProp\", value);\nif (status != napi_ok) return status;\n```\n\nIndexed properties can be set in a similar manner. Consider the following\nJavaScript snippet:\n\n```js\nconst arr = [];\narr[123] = 'hello';\n```\n\nThe equivalent can be done using Node-API values with the following snippet:\n\n```c\nnapi_status status = napi_generic_failure;\n\n// const arr = [];\nnapi_value arr, value;\nstatus = napi_create_array(env, &arr);\nif (status != napi_ok) return status;\n\n// Create a napi_value for 'hello'\nstatus = napi_create_string_utf8(env, \"hello\", NAPI_AUTO_LENGTH, &value);\nif (status != napi_ok) return status;\n\n// arr[123] = 'hello';\nstatus = napi_set_element(env, arr, 123, value);\nif (status != napi_ok) return status;\n```\n\nProperties can be retrieved using the APIs described in this section.\nConsider the following JavaScript snippet:\n\n```js\nconst arr = [];\nconst value = arr[123];\n```\n\nThe following is the approximate equivalent of the Node-API counterpart:\n\n```c\nnapi_status status = napi_generic_failure;\n\n// const arr = []\nnapi_value arr, value;\nstatus = napi_create_array(env, &arr);\nif (status != napi_ok) return status;\n\n// const value = arr[123]\nstatus = napi_get_element(env, arr, 123, &value);\nif (status != napi_ok) return status;\n```\n\nFinally, multiple properties can also be defined on an object for performance\nreasons. Consider the following JavaScript:\n\n```js\nconst obj = {};\nObject.defineProperties(obj, {\n  'foo': { value: 123, writable: true, configurable: true, enumerable: true },\n  'bar': { value: 456, writable: true, configurable: true, enumerable: true },\n});\n```\n\nThe following is the approximate equivalent of the Node-API counterpart:\n\n```c\nnapi_status status = napi_status_generic_failure;\n\n// const obj = {};\nnapi_value obj;\nstatus = napi_create_object(env, &obj);\nif (status != napi_ok) return status;\n\n// Create napi_values for 123 and 456\nnapi_value fooValue, barValue;\nstatus = napi_create_int32(env, 123, &fooValue);\nif (status != napi_ok) return status;\nstatus = napi_create_int32(env, 456, &barValue);\nif (status != napi_ok) return status;\n\n// Set the properties\nnapi_property_descriptor descriptors[] = {\n  { \"foo\", NULL, NULL, NULL, NULL, fooValue, napi_writable | napi_configurable, NULL },\n  { \"bar\", NULL, NULL, NULL, NULL, barValue, napi_writable | napi_configurable, NULL }\n}\nstatus = napi_define_properties(env,\n                                obj,\n                                sizeof(descriptors) / sizeof(descriptors[0]),\n                                descriptors);\nif (status != napi_ok) return status;\n```","summary":"Node-API exposes a set of APIs to get and set properties on JavaScript objects.","examples":[{"language":"js","displayName":null,"code":"const obj = {};\nobj.myProp = 123;"},{"language":"c","displayName":null,"code":"napi_status status = napi_generic_failure;\n\n// const obj = {}\nnapi_value obj, value;\nstatus = napi_create_object(env, &obj);\nif (status != napi_ok) return status;\n\n// Create a napi_value for 123\nstatus = napi_create_int32(env, 123, &value);\nif (status != napi_ok) return status;\n\n// obj.myProp = 123\nstatus = napi_set_named_property(env, obj, \"myProp\", value);\nif (status != napi_ok) return status;"},{"language":"js","displayName":null,"code":"const arr = [];\narr[123] = 'hello';"},{"language":"c","displayName":null,"code":"napi_status status = napi_generic_failure;\n\n// const arr = [];\nnapi_value arr, value;\nstatus = napi_create_array(env, &arr);\nif (status != napi_ok) return status;\n\n// Create a napi_value for 'hello'\nstatus = napi_create_string_utf8(env, \"hello\", NAPI_AUTO_LENGTH, &value);\nif (status != napi_ok) return status;\n\n// arr[123] = 'hello';\nstatus = napi_set_element(env, arr, 123, value);\nif (status != napi_ok) return status;"},{"language":"js","displayName":null,"code":"const arr = [];\nconst value = arr[123];"},{"language":"c","displayName":null,"code":"napi_status status = napi_generic_failure;\n\n// const arr = []\nnapi_value arr, value;\nstatus = napi_create_array(env, &arr);\nif (status != napi_ok) return status;\n\n// const value = arr[123]\nstatus = napi_get_element(env, arr, 123, &value);\nif (status != napi_ok) return status;"},{"language":"js","displayName":null,"code":"const obj = {};\nObject.defineProperties(obj, {\n  'foo': { value: 123, writable: true, configurable: true, enumerable: true },\n  'bar': { value: 456, writable: true, configurable: true, enumerable: true },\n});"},{"language":"c","displayName":null,"code":"napi_status status = napi_status_generic_failure;\n\n// const obj = {};\nnapi_value obj;\nstatus = napi_create_object(env, &obj);\nif (status != napi_ok) return status;\n\n// Create napi_values for 123 and 456\nnapi_value fooValue, barValue;\nstatus = napi_create_int32(env, 123, &fooValue);\nif (status != napi_ok) return status;\nstatus = napi_create_int32(env, 456, &barValue);\nif (status != napi_ok) return status;\n\n// Set the properties\nnapi_property_descriptor descriptors[] = {\n  { \"foo\", NULL, NULL, NULL, NULL, fooValue, napi_writable | napi_configurable, NULL },\n  { \"bar\", NULL, NULL, NULL, NULL, barValue, napi_writable | napi_configurable, NULL }\n}\nstatus = napi_define_properties(env,\n                                obj,\n                                sizeof(descriptors) / sizeof(descriptors[0]),\n                                descriptors);\nif (status != napi_ok) return status;"}],"children":[{"kind":"section","id":"structures","name":"Structures","title":"Structures","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"","summary":"","examples":[],"children":[{"kind":"section","id":"napi_property_attributes","name":"napi_property_attributes","title":"`napi_property_attributes`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v14.12.0"],"prUrl":"https://github.com/nodejs/node/pull/35214","commit":null,"description":"added `napi_default_method` and `napi_default_property`."}],"description":"```c\ntypedef enum {\n  napi_default = 0,\n  napi_writable = 1 << 0,\n  napi_enumerable = 1 << 1,\n  napi_configurable = 1 << 2,\n\n  // Used with napi_define_class to distinguish static properties\n  // from instance properties. Ignored by napi_define_properties.\n  napi_static = 1 << 10,\n\n  // Default for class methods.\n  napi_default_method = napi_writable | napi_configurable,\n\n  // Default for object properties, like in JS obj[prop].\n  napi_default_jsproperty = napi_writable |\n                          napi_enumerable |\n                          napi_configurable,\n} napi_property_attributes;\n```\n\n`napi_property_attributes` are bit flags used to control the behavior of\nproperties set on a JavaScript object. Other than `napi_static` they\ncorrespond to the attributes listed in [Section property attributes](https://tc39.es/ecma262/#sec-property-attributes)\nof the [ECMAScript Language Specification](https://tc39.es/ecma262/).\nThey can be one or more of the following bit flags:\n\n* `napi_default`: No explicit attributes are set on the property. By default, a\n  property is read only, not enumerable and not configurable.\n* `napi_writable`: The property is writable.\n* `napi_enumerable`: The property is enumerable.\n* `napi_configurable`: The property is configurable as defined in\n  [Section property attributes](https://tc39.es/ecma262/#sec-property-attributes) of the [ECMAScript Language Specification](https://tc39.es/ecma262/).\n* `napi_static`: The property will be defined as a static property on a class as\n  opposed to an instance property, which is the default. This is used only by\n  [`napi_define_class`](#napi_define_class). It is ignored by `napi_define_properties`.\n* `napi_default_method`: Like a method in a JS class, the property is\n  configurable and writable, but not enumerable.\n* `napi_default_jsproperty`: Like a property set via assignment in JavaScript,\n  the property is writable, enumerable, and configurable.","summary":"`napi_property_attributes` are bit flags used to control the behavior of properties set on a JavaScript object. Other than `napi_static` they correspond to the attributes listed in Section property attributes of the ECMAScript Language Specification. They can be one or more of the following bit flags:","examples":[{"language":"c","displayName":null,"code":"typedef enum {\n  napi_default = 0,\n  napi_writable = 1 << 0,\n  napi_enumerable = 1 << 1,\n  napi_configurable = 1 << 2,\n\n  // Used with napi_define_class to distinguish static properties\n  // from instance properties. Ignored by napi_define_properties.\n  napi_static = 1 << 10,\n\n  // Default for class methods.\n  napi_default_method = napi_writable | napi_configurable,\n\n  // Default for object properties, like in JS obj[prop].\n  napi_default_jsproperty = napi_writable |\n                          napi_enumerable |\n                          napi_configurable,\n} napi_property_attributes;"}],"children":[]},{"kind":"section","id":"napi_property_descriptor","name":"napi_property_descriptor","title":"`napi_property_descriptor`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"```c\ntypedef struct {\n  // One of utf8name or name should be NULL.\n  const char* utf8name;\n  napi_value name;\n\n  napi_callback method;\n  napi_callback getter;\n  napi_callback setter;\n  napi_value value;\n\n  napi_property_attributes attributes;\n  void* data;\n} napi_property_descriptor;\n```\n\n* `utf8name`: Optional string describing the key for the property,\n  encoded as UTF8. One of `utf8name` or `name` must be provided for the\n  property.\n* `name`: Optional `napi_value` that points to a JavaScript string or symbol\n  to be used as the key for the property. One of `utf8name` or `name` must\n  be provided for the property.\n* `value`: The value that's retrieved by a get access of the property if the\n  property is a data property. If this is passed in, set `getter`, `setter`,\n  `method` and `data` to `NULL` (since these members won't be used).\n* `getter`: A function to call when a get access of the property is performed.\n  If this is passed in, set `value` and `method` to `NULL` (since these members\n  won't be used). The given function is called implicitly by the runtime when\n  the property is accessed from JavaScript code (or if a get on the property is\n  performed using a Node-API call). [`napi_callback`](#napi_callback) provides more details.\n* `setter`: A function to call when a set access of the property is performed.\n  If this is passed in, set `value` and `method` to `NULL` (since these members\n  won't be used). The given function is called implicitly by the runtime when\n  the property is set from JavaScript code (or if a set on the property is\n  performed using a Node-API call). [`napi_callback`](#napi_callback) provides more details.\n* `method`: Set this to make the property descriptor object's `value`\n  property to be a JavaScript function represented by `method`. If this is\n  passed in, set `value`, `getter` and `setter` to `NULL` (since these members\n  won't be used). [`napi_callback`](#napi_callback) provides more details.\n* `attributes`: The attributes associated with the particular property. See\n  [`napi_property_attributes`](#napi_property_attributes).\n* `data`: The callback data passed into `method`, `getter` and `setter` if this\n  function is invoked.","summary":"","examples":[{"language":"c","displayName":null,"code":"typedef struct {\n  // One of utf8name or name should be NULL.\n  const char* utf8name;\n  napi_value name;\n\n  napi_callback method;\n  napi_callback getter;\n  napi_callback setter;\n  napi_value value;\n\n  napi_property_attributes attributes;\n  void* data;\n} napi_property_descriptor;"}],"children":[]}]},{"kind":"section","id":"functions","name":"Functions","title":"Functions","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"","summary":"","examples":[],"children":[{"kind":"section","id":"napi_get_property_names","name":"napi_get_property_names","title":"`napi_get_property_names`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_get_property_names(napi_env env,\n                                    napi_value object,\n                                    napi_value* result);\n```\n\n* `[in] env`: The environment that the Node-API call is invoked under.\n* `[in] object`: The object from which to retrieve the properties.\n* `[out] result`: A `napi_value` representing an array of JavaScript values\n  that represent the property names of the object. The API can be used to\n  iterate over `result` using [`napi_get_array_length`](#napi_get_array_length)\n  and [`napi_get_element`](#napi_get_element).\n\nReturns `napi_ok` if the API succeeded.\n\nThis API returns the names of the enumerable properties of `object` as an array\nof strings. The properties of `object` whose key is a symbol will not be\nincluded.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_get_property_names(napi_env env,\n                                    napi_value object,\n                                    napi_value* result);"}],"children":[]},{"kind":"section","id":"napi_get_all_property_names","name":"napi_get_all_property_names","title":"`napi_get_all_property_names`","scope":"module","overloadOf":null,"stability":null,"added":["v13.7.0","v12.17.0","v10.20.0"],"deprecated":[],"removed":[],"napiVersion":[6],"changes":[],"description":"```c\nnapi_get_all_property_names(napi_env env,\n                            napi_value object,\n                            napi_key_collection_mode key_mode,\n                            napi_key_filter key_filter,\n                            napi_key_conversion key_conversion,\n                            napi_value* result);\n```\n\n* `[in] env`: The environment that the Node-API call is invoked under.\n* `[in] object`: The object from which to retrieve the properties.\n* `[in] key_mode`: Whether to retrieve prototype properties as well.\n* `[in] key_filter`: Which properties to retrieve\n  (enumerable/readable/writable).\n* `[in] key_conversion`: Whether to convert numbered property keys to strings.\n* `[out] result`: A `napi_value` representing an array of JavaScript values\n  that represent the property names of the object. [`napi_get_array_length`](#napi_get_array_length)\n  and [`napi_get_element`](#napi_get_element) can be used to iterate over `result`.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API returns an array containing the names of the available properties\nof this object.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_get_all_property_names(napi_env env,\n                            napi_value object,\n                            napi_key_collection_mode key_mode,\n                            napi_key_filter key_filter,\n                            napi_key_conversion key_conversion,\n                            napi_value* result);"}],"children":[]},{"kind":"section","id":"napi_set_property","name":"napi_set_property","title":"`napi_set_property`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_set_property(napi_env env,\n                              napi_value object,\n                              napi_value key,\n                              napi_value value);\n```\n\n* `[in] env`: The environment that the Node-API call is invoked under.\n* `[in] object`: The object on which to set the property.\n* `[in] key`: The name of the property to set.\n* `[in] value`: The property value.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API set a property on the `Object` passed in.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_set_property(napi_env env,\n                              napi_value object,\n                              napi_value key,\n                              napi_value value);"}],"children":[]},{"kind":"section","id":"napi_get_property","name":"napi_get_property","title":"`napi_get_property`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_get_property(napi_env env,\n                              napi_value object,\n                              napi_value key,\n                              napi_value* result);\n```\n\n* `[in] env`: The environment that the Node-API call is invoked under.\n* `[in] object`: The object from which to retrieve the property.\n* `[in] key`: The name of the property to retrieve.\n* `[out] result`: The value of the property.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API gets the requested property from the `Object` passed in.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_get_property(napi_env env,\n                              napi_value object,\n                              napi_value key,\n                              napi_value* result);"}],"children":[]},{"kind":"section","id":"napi_has_property","name":"napi_has_property","title":"`napi_has_property`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_has_property(napi_env env,\n                              napi_value object,\n                              napi_value key,\n                              bool* result);\n```\n\n* `[in] env`: The environment that the Node-API call is invoked under.\n* `[in] object`: The object to query.\n* `[in] key`: The name of the property whose existence to check.\n* `[out] result`: Whether the property exists on the object or not.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API checks if the `Object` passed in has the named property.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_has_property(napi_env env,\n                              napi_value object,\n                              napi_value key,\n                              bool* result);"}],"children":[]},{"kind":"section","id":"napi_delete_property","name":"napi_delete_property","title":"`napi_delete_property`","scope":"module","overloadOf":null,"stability":null,"added":["v8.2.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_delete_property(napi_env env,\n                                 napi_value object,\n                                 napi_value key,\n                                 bool* result);\n```\n\n* `[in] env`: The environment that the Node-API call is invoked under.\n* `[in] object`: The object to query.\n* `[in] key`: The name of the property to delete.\n* `[out] result`: Whether the property deletion succeeded or not. `result` can\n  optionally be ignored by passing `NULL`.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API attempts to delete the `key` own property from `object`.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_delete_property(napi_env env,\n                                 napi_value object,\n                                 napi_value key,\n                                 bool* result);"}],"children":[]},{"kind":"section","id":"napi_has_own_property","name":"napi_has_own_property","title":"`napi_has_own_property`","scope":"module","overloadOf":null,"stability":null,"added":["v8.2.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_has_own_property(napi_env env,\n                                  napi_value object,\n                                  napi_value key,\n                                  bool* result);\n```\n\n* `[in] env`: The environment that the Node-API call is invoked under.\n* `[in] object`: The object to query.\n* `[in] key`: The name of the own property whose existence to check.\n* `[out] result`: Whether the own property exists on the object or not.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API checks if the `Object` passed in has the named own property. `key` must\nbe a `string` or a `symbol`, or an error will be thrown. Node-API will not\nperform any conversion between data types.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_has_own_property(napi_env env,\n                                  napi_value object,\n                                  napi_value key,\n                                  bool* result);"}],"children":[]},{"kind":"section","id":"napi_set_named_property","name":"napi_set_named_property","title":"`napi_set_named_property`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_set_named_property(napi_env env,\n                                    napi_value object,\n                                    const char* utf8Name,\n                                    napi_value value);\n```\n\n* `[in] env`: The environment that the Node-API call is invoked under.\n* `[in] object`: The object on which to set the property.\n* `[in] utf8Name`: The name of the property to set.\n* `[in] value`: The property value.\n\nReturns `napi_ok` if the API succeeded.\n\nThis method is equivalent to calling [`napi_set_property`](#napi_set_property) with a `napi_value`\ncreated from the string passed in as `utf8Name`.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_set_named_property(napi_env env,\n                                    napi_value object,\n                                    const char* utf8Name,\n                                    napi_value value);"}],"children":[]},{"kind":"section","id":"napi_get_named_property","name":"napi_get_named_property","title":"`napi_get_named_property`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_get_named_property(napi_env env,\n                                    napi_value object,\n                                    const char* utf8Name,\n                                    napi_value* result);\n```\n\n* `[in] env`: The environment that the Node-API call is invoked under.\n* `[in] object`: The object from which to retrieve the property.\n* `[in] utf8Name`: The name of the property to get.\n* `[out] result`: The value of the property.\n\nReturns `napi_ok` if the API succeeded.\n\nThis method is equivalent to calling [`napi_get_property`](#napi_get_property) with a `napi_value`\ncreated from the string passed in as `utf8Name`.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_get_named_property(napi_env env,\n                                    napi_value object,\n                                    const char* utf8Name,\n                                    napi_value* result);"}],"children":[]},{"kind":"section","id":"napi_has_named_property","name":"napi_has_named_property","title":"`napi_has_named_property`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_has_named_property(napi_env env,\n                                    napi_value object,\n                                    const char* utf8Name,\n                                    bool* result);\n```\n\n* `[in] env`: The environment that the Node-API call is invoked under.\n* `[in] object`: The object to query.\n* `[in] utf8Name`: The name of the property whose existence to check.\n* `[out] result`: Whether the property exists on the object or not.\n\nReturns `napi_ok` if the API succeeded.\n\nThis method is equivalent to calling [`napi_has_property`](#napi_has_property) with a `napi_value`\ncreated from the string passed in as `utf8Name`.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_has_named_property(napi_env env,\n                                    napi_value object,\n                                    const char* utf8Name,\n                                    bool* result);"}],"children":[]},{"kind":"section","id":"napi_set_element","name":"napi_set_element","title":"`napi_set_element`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_set_element(napi_env env,\n                             napi_value object,\n                             uint32_t index,\n                             napi_value value);\n```\n\n* `[in] env`: The environment that the Node-API call is invoked under.\n* `[in] object`: The object from which to set the properties.\n* `[in] index`: The index of the property to set.\n* `[in] value`: The property value.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API sets an element on the `Object` passed in.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_set_element(napi_env env,\n                             napi_value object,\n                             uint32_t index,\n                             napi_value value);"}],"children":[]},{"kind":"section","id":"napi_get_element","name":"napi_get_element","title":"`napi_get_element`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_get_element(napi_env env,\n                             napi_value object,\n                             uint32_t index,\n                             napi_value* result);\n```\n\n* `[in] env`: The environment that the Node-API call is invoked under.\n* `[in] object`: The object from which to retrieve the property.\n* `[in] index`: The index of the property to get.\n* `[out] result`: The value of the property.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API gets the element at the requested index.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_get_element(napi_env env,\n                             napi_value object,\n                             uint32_t index,\n                             napi_value* result);"}],"children":[]},{"kind":"section","id":"napi_has_element","name":"napi_has_element","title":"`napi_has_element`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_has_element(napi_env env,\n                             napi_value object,\n                             uint32_t index,\n                             bool* result);\n```\n\n* `[in] env`: The environment that the Node-API call is invoked under.\n* `[in] object`: The object to query.\n* `[in] index`: The index of the property whose existence to check.\n* `[out] result`: Whether the property exists on the object or not.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API returns if the `Object` passed in has an element at the\nrequested index.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_has_element(napi_env env,\n                             napi_value object,\n                             uint32_t index,\n                             bool* result);"}],"children":[]},{"kind":"section","id":"napi_delete_element","name":"napi_delete_element","title":"`napi_delete_element`","scope":"module","overloadOf":null,"stability":null,"added":["v8.2.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_delete_element(napi_env env,\n                                napi_value object,\n                                uint32_t index,\n                                bool* result);\n```\n\n* `[in] env`: The environment that the Node-API call is invoked under.\n* `[in] object`: The object to query.\n* `[in] index`: The index of the property to delete.\n* `[out] result`: Whether the element deletion succeeded or not. `result` can\n  optionally be ignored by passing `NULL`.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API attempts to delete the specified `index` from `object`.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_delete_element(napi_env env,\n                                napi_value object,\n                                uint32_t index,\n                                bool* result);"}],"children":[]},{"kind":"section","id":"napi_define_properties","name":"napi_define_properties","title":"`napi_define_properties`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_define_properties(napi_env env,\n                                   napi_value object,\n                                   size_t property_count,\n                                   const napi_property_descriptor* properties);\n```\n\n* `[in] env`: The environment that the Node-API call is invoked under.\n* `[in] object`: The object from which to retrieve the properties.\n* `[in] property_count`: The number of elements in the `properties` array.\n* `[in] properties`: The array of property descriptors.\n\nReturns `napi_ok` if the API succeeded.\n\nThis method allows the efficient definition of multiple properties on a given\nobject. The properties are defined using property descriptors (see\n[`napi_property_descriptor`](#napi_property_descriptor)). Given an array of such property descriptors,\nthis API will set the properties on the object one at a time, as defined by\n`DefineOwnProperty()` (described in [Section DefineOwnProperty](https://tc39.es/ecma262/#sec-ordinary-object-internal-methods-and-internal-slots-defineownproperty-p-desc) of the ECMA-262\nspecification).","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_define_properties(napi_env env,\n                                   napi_value object,\n                                   size_t property_count,\n                                   const napi_property_descriptor* properties);"}],"children":[]},{"kind":"section","id":"napi_object_freeze","name":"napi_object_freeze","title":"`napi_object_freeze`","scope":"module","overloadOf":null,"stability":null,"added":["v14.14.0","v12.20.0"],"deprecated":[],"removed":[],"napiVersion":[8],"changes":[],"description":"```c\nnapi_status napi_object_freeze(napi_env env,\n                               napi_value object);\n```\n\n* `[in] env`: The environment that the Node-API call is invoked under.\n* `[in] object`: The object to freeze.\n\nReturns `napi_ok` if the API succeeded.\n\nThis method freezes a given object. This prevents new properties from\nbeing added to it, existing properties from being removed, prevents\nchanging the enumerability, configurability, or writability of existing\nproperties, and prevents the values of existing properties from being changed.\nIt also prevents the object's prototype from being changed. This is described\nin [Section 19.1.2.6](https://tc39.es/ecma262/#sec-object.freeze) of the\nECMA-262 specification.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_object_freeze(napi_env env,\n                               napi_value object);"}],"children":[]},{"kind":"section","id":"napi_object_seal","name":"napi_object_seal","title":"`napi_object_seal`","scope":"module","overloadOf":null,"stability":null,"added":["v14.14.0","v12.20.0"],"deprecated":[],"removed":[],"napiVersion":[8],"changes":[],"description":"```c\nnapi_status napi_object_seal(napi_env env,\n                             napi_value object);\n```\n\n* `[in] env`: The environment that the Node-API call is invoked under.\n* `[in] object`: The object to seal.\n\nReturns `napi_ok` if the API succeeded.\n\nThis method seals a given object. This prevents new properties from being\nadded to it, as well as marking all existing properties as non-configurable.\nThis is described in [Section 19.1.2.20](https://tc39.es/ecma262/#sec-object.seal)\nof the ECMA-262 specification.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_object_seal(napi_env env,\n                             napi_value object);"}],"children":[]},{"kind":"section","id":"node_api_set_prototype","name":"node_api_set_prototype","title":"`node_api_set_prototype`","scope":"module","overloadOf":null,"stability":{"index":"1","description":"Experimental"},"added":["v25.4.0","v24.13.1"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"```c\nnapi_status node_api_set_prototype(napi_env env,\n                                   napi_value object,\n                                   napi_value value);\n```\n\n* `[in] env`: The environment that the Node-API call is invoked under.\n* `[in] object`: The object on which to set the prototype.\n* `[in] value`: The prototype value.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API sets the prototype of the `Object` passed in.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status node_api_set_prototype(napi_env env,\n                                   napi_value object,\n                                   napi_value value);"}],"children":[]}]}]},{"kind":"section","id":"working-with-javascript-functions","name":"Working with JavaScript functions","title":"Working with JavaScript functions","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"Node-API provides a set of APIs that allow JavaScript code to\ncall back into native code. Node-APIs that support calling back\ninto native code take in a callback functions represented by\nthe `napi_callback` type. When the JavaScript VM calls back to\nnative code, the `napi_callback` function provided is invoked. The APIs\ndocumented in this section allow the callback function to do the\nfollowing:\n\n* Get information about the context in which the callback was invoked.\n* Get the arguments passed into the callback.\n* Return a `napi_value` back from the callback.\n\nAdditionally, Node-API provides a set of functions which allow calling\nJavaScript functions from native code. One can either call a function\nlike a regular JavaScript function call, or as a constructor\nfunction.\n\nAny non-`NULL` data which is passed to this API via the `data` field of the\n`napi_property_descriptor` items can be associated with `object` and freed\nwhenever `object` is garbage-collected by passing both `object` and the data to\n[`napi_add_finalizer`](#napi_add_finalizer).","summary":"Node-API provides a set of APIs that allow JavaScript code to call back into native code. Node-APIs that support calling back into native code take in a callback functions represented by the `napi_callback` type. When the JavaScript VM calls back to native code, the `napi_callback` function provided is invoked. The APIs documented in this section allow the callback function to do the following:","examples":[],"children":[{"kind":"section","id":"napi_call_function","name":"napi_call_function","title":"`napi_call_function`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nNAPI_EXTERN napi_status napi_call_function(napi_env env,\n                                           napi_value recv,\n                                           napi_value func,\n                                           size_t argc,\n                                           const napi_value* argv,\n                                           napi_value* result);\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] recv`: The `this` value passed to the called function.\n* `[in] func`: `napi_value` representing the JavaScript function to be invoked.\n* `[in] argc`: The count of elements in the `argv` array.\n* `[in] argv`: Array of `napi_values` representing JavaScript values passed in\n  as arguments to the function.\n* `[out] result`: `napi_value` representing the JavaScript object returned.\n\nReturns `napi_ok` if the API succeeded.\n\nThis method allows a JavaScript function object to be called from a native\nadd-on. This is the primary mechanism of calling back *from* the add-on's\nnative code *into* JavaScript. For the special case of calling into JavaScript\nafter an async operation, see [`napi_make_callback`](#napi_make_callback).\n\nA sample use case might look as follows. Consider the following JavaScript\nsnippet:\n\n```js\nfunction AddTwo(num) {\n  return num + 2;\n}\nglobal.AddTwo = AddTwo;\n```\n\nThen, the above function can be invoked from a native add-on using the\nfollowing code:\n\n```c\n// Get the function named \"AddTwo\" on the global object\nnapi_value global, add_two, arg;\nnapi_status status = napi_get_global(env, &global);\nif (status != napi_ok) return;\n\nstatus = napi_get_named_property(env, global, \"AddTwo\", &add_two);\nif (status != napi_ok) return;\n\n// const arg = 1337\nstatus = napi_create_int32(env, 1337, &arg);\nif (status != napi_ok) return;\n\nnapi_value* argv = &arg;\nsize_t argc = 1;\n\n// AddTwo(arg);\nnapi_value return_val;\nstatus = napi_call_function(env, global, add_two, argc, argv, &return_val);\nif (status != napi_ok) return;\n\n// Convert the result back to a native type\nint32_t result;\nstatus = napi_get_value_int32(env, return_val, &result);\nif (status != napi_ok) return;\n```","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"NAPI_EXTERN napi_status napi_call_function(napi_env env,\n                                           napi_value recv,\n                                           napi_value func,\n                                           size_t argc,\n                                           const napi_value* argv,\n                                           napi_value* result);"},{"language":"js","displayName":null,"code":"function AddTwo(num) {\n  return num + 2;\n}\nglobal.AddTwo = AddTwo;"},{"language":"c","displayName":null,"code":"// Get the function named \"AddTwo\" on the global object\nnapi_value global, add_two, arg;\nnapi_status status = napi_get_global(env, &global);\nif (status != napi_ok) return;\n\nstatus = napi_get_named_property(env, global, \"AddTwo\", &add_two);\nif (status != napi_ok) return;\n\n// const arg = 1337\nstatus = napi_create_int32(env, 1337, &arg);\nif (status != napi_ok) return;\n\nnapi_value* argv = &arg;\nsize_t argc = 1;\n\n// AddTwo(arg);\nnapi_value return_val;\nstatus = napi_call_function(env, global, add_two, argc, argv, &return_val);\nif (status != napi_ok) return;\n\n// Convert the result back to a native type\nint32_t result;\nstatus = napi_get_value_int32(env, return_val, &result);\nif (status != napi_ok) return;"}],"children":[]},{"kind":"section","id":"napi_create_function","name":"napi_create_function","title":"`napi_create_function`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_create_function(napi_env env,\n                                 const char* utf8name,\n                                 size_t length,\n                                 napi_callback cb,\n                                 void* data,\n                                 napi_value* result);\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] utf8Name`: Optional name of the function encoded as UTF8. This is\n  visible within JavaScript as the new function object's `name` property.\n* `[in] length`: The length of the `utf8name` in bytes, or `NAPI_AUTO_LENGTH` if\n  it is null-terminated.\n* `[in] cb`: The native function which should be called when this function\n  object is invoked. [`napi_callback`](#napi_callback) provides more details.\n* `[in] data`: User-provided data context. This will be passed back into the\n  function when invoked later.\n* `[out] result`: `napi_value` representing the JavaScript function object for\n  the newly created function.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API allows an add-on author to create a function object in native code.\nThis is the primary mechanism to allow calling *into* the add-on's native code\n*from* JavaScript.\n\nThe newly created function is not automatically visible from script after this\ncall. Instead, a property must be explicitly set on any object that is visible\nto JavaScript, in order for the function to be accessible from script.\n\nIn order to expose a function as part of the\nadd-on's module exports, set the newly created function on the exports\nobject. A sample module might look as follows:\n\n```c\nnapi_value SayHello(napi_env env, napi_callback_info info) {\n  printf(\"Hello\\n\");\n  return NULL;\n}\n\nnapi_value Init(napi_env env, napi_value exports) {\n  napi_status status;\n\n  napi_value fn;\n  status = napi_create_function(env, NULL, 0, SayHello, NULL, &fn);\n  if (status != napi_ok) return NULL;\n\n  status = napi_set_named_property(env, exports, \"sayHello\", fn);\n  if (status != napi_ok) return NULL;\n\n  return exports;\n}\n\nNAPI_MODULE(NODE_GYP_MODULE_NAME, Init)\n```\n\nGiven the above code, the add-on can be used from JavaScript as follows:\n\n```js\nconst myaddon = require('./addon');\nmyaddon.sayHello();\n```\n\nThe string passed to `require()` is the name of the target in `binding.gyp`\nresponsible for creating the `.node` file.\n\nAny non-`NULL` data which is passed to this API via the `data` parameter can\nbe associated with the resulting JavaScript function (which is returned in the\n`result` parameter) and freed whenever the function is garbage-collected by\npassing both the JavaScript function and the data to [`napi_add_finalizer`](#napi_add_finalizer).\n\nJavaScript `Function`s are described in [Section Function objects](https://tc39.es/ecma262/#sec-function-objects) of the ECMAScript\nLanguage Specification.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_create_function(napi_env env,\n                                 const char* utf8name,\n                                 size_t length,\n                                 napi_callback cb,\n                                 void* data,\n                                 napi_value* result);"},{"language":"c","displayName":null,"code":"napi_value SayHello(napi_env env, napi_callback_info info) {\n  printf(\"Hello\\n\");\n  return NULL;\n}\n\nnapi_value Init(napi_env env, napi_value exports) {\n  napi_status status;\n\n  napi_value fn;\n  status = napi_create_function(env, NULL, 0, SayHello, NULL, &fn);\n  if (status != napi_ok) return NULL;\n\n  status = napi_set_named_property(env, exports, \"sayHello\", fn);\n  if (status != napi_ok) return NULL;\n\n  return exports;\n}\n\nNAPI_MODULE(NODE_GYP_MODULE_NAME, Init)"},{"language":"js","displayName":null,"code":"const myaddon = require('./addon');\nmyaddon.sayHello();"}],"children":[]},{"kind":"section","id":"napi_get_cb_info","name":"napi_get_cb_info","title":"`napi_get_cb_info`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_get_cb_info(napi_env env,\n                             napi_callback_info cbinfo,\n                             size_t* argc,\n                             napi_value* argv,\n                             napi_value* thisArg,\n                             void** data)\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] cbinfo`: The callback info passed into the callback function.\n* `[in-out] argc`: Specifies the length of the provided `argv` array and\n  receives the actual count of arguments. `argc` can\n  optionally be ignored by passing `NULL`.\n* `[out] argv`: C array of `napi_value`s to which the arguments will be\n  copied. If there are more arguments than the provided count, only the\n  requested number of arguments are copied. If there are fewer arguments\n  provided than claimed, the rest of `argv` is filled with `napi_value` values\n  that represent `undefined`. `argv` can optionally be ignored by\n  passing `NULL`.\n* `[out] thisArg`: Receives the JavaScript `this` argument for the call.\n  `thisArg` can optionally be ignored by passing `NULL`.\n* `[out] data`: Receives the data pointer for the callback. `data` can\n  optionally be ignored by passing `NULL`.\n\nReturns `napi_ok` if the API succeeded.\n\nThis method is used within a callback function to retrieve details about the\ncall like the arguments and the `this` pointer from a given callback info.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_get_cb_info(napi_env env,\n                             napi_callback_info cbinfo,\n                             size_t* argc,\n                             napi_value* argv,\n                             napi_value* thisArg,\n                             void** data)"}],"children":[]},{"kind":"section","id":"napi_get_new_target","name":"napi_get_new_target","title":"`napi_get_new_target`","scope":"module","overloadOf":null,"stability":null,"added":["v8.6.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_get_new_target(napi_env env,\n                                napi_callback_info cbinfo,\n                                napi_value* result)\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] cbinfo`: The callback info passed into the callback function.\n* `[out] result`: The `new.target` of the constructor call.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API returns the `new.target` of the constructor call. If the current\ncallback is not a constructor call, the result is `NULL`.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_get_new_target(napi_env env,\n                                napi_callback_info cbinfo,\n                                napi_value* result)"}],"children":[]},{"kind":"section","id":"napi_new_instance","name":"napi_new_instance","title":"`napi_new_instance`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_new_instance(napi_env env,\n                              napi_value cons,\n                              size_t argc,\n                              napi_value* argv,\n                              napi_value* result)\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] cons`: `napi_value` representing the JavaScript function to be invoked\n  as a constructor.\n* `[in] argc`: The count of elements in the `argv` array.\n* `[in] argv`: Array of JavaScript values as `napi_value` representing the\n  arguments to the constructor. If `argc` is zero this parameter may be\n  omitted by passing in `NULL`.\n* `[out] result`: `napi_value` representing the JavaScript object returned,\n  which in this case is the constructed object.\n\nThis method is used to instantiate a new JavaScript value using a given\n`napi_value` that represents the constructor for the object. For example,\nconsider the following snippet:\n\n```js\nfunction MyObject(param) {\n  this.param = param;\n}\n\nconst arg = 'hello';\nconst value = new MyObject(arg);\n```\n\nThe following can be approximated in Node-API using the following snippet:\n\n```c\n// Get the constructor function MyObject\nnapi_value global, constructor, arg, value;\nnapi_status status = napi_get_global(env, &global);\nif (status != napi_ok) return;\n\nstatus = napi_get_named_property(env, global, \"MyObject\", &constructor);\nif (status != napi_ok) return;\n\n// const arg = \"hello\"\nstatus = napi_create_string_utf8(env, \"hello\", NAPI_AUTO_LENGTH, &arg);\nif (status != napi_ok) return;\n\nnapi_value* argv = &arg;\nsize_t argc = 1;\n\n// const value = new MyObject(arg)\nstatus = napi_new_instance(env, constructor, argc, argv, &value);\n```\n\nReturns `napi_ok` if the API succeeded.","summary":"This method is used to instantiate a new JavaScript value using a given `napi_value` that represents the constructor for the object. For example, consider the following snippet:","examples":[{"language":"c","displayName":null,"code":"napi_status napi_new_instance(napi_env env,\n                              napi_value cons,\n                              size_t argc,\n                              napi_value* argv,\n                              napi_value* result)"},{"language":"js","displayName":null,"code":"function MyObject(param) {\n  this.param = param;\n}\n\nconst arg = 'hello';\nconst value = new MyObject(arg);"},{"language":"c","displayName":null,"code":"// Get the constructor function MyObject\nnapi_value global, constructor, arg, value;\nnapi_status status = napi_get_global(env, &global);\nif (status != napi_ok) return;\n\nstatus = napi_get_named_property(env, global, \"MyObject\", &constructor);\nif (status != napi_ok) return;\n\n// const arg = \"hello\"\nstatus = napi_create_string_utf8(env, \"hello\", NAPI_AUTO_LENGTH, &arg);\nif (status != napi_ok) return;\n\nnapi_value* argv = &arg;\nsize_t argc = 1;\n\n// const value = new MyObject(arg)\nstatus = napi_new_instance(env, constructor, argc, argv, &value);"}],"children":[]}]},{"kind":"section","id":"object-wrap","name":"Object wrap","title":"Object wrap","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"Node-API offers a way to \"wrap\" C++ classes and instances so that the class\nconstructor and methods can be called from JavaScript.\n\n1. The [`napi_define_class`](#napi_define_class) API defines a JavaScript class with constructor,\n   static properties and methods, and instance properties and methods that\n   correspond to the C++ class.\n2. When JavaScript code invokes the constructor, the constructor callback\n   uses [`napi_wrap`](#napi_wrap) to wrap a new C++ instance in a JavaScript object,\n   then returns the wrapper object.\n3. When JavaScript code invokes a method or property accessor on the class,\n   the corresponding `napi_callback` C++ function is invoked. For an instance\n   callback, [`napi_unwrap`](#napi_unwrap) obtains the C++ instance that is the target of\n   the call.\n\nFor wrapped objects it may be difficult to distinguish between a function\ncalled on a class prototype and a function called on an instance of a class.\nA common pattern used to address this problem is to save a persistent\nreference to the class constructor for later `instanceof` checks.\n\n```c\nnapi_value MyClass_constructor = NULL;\nstatus = napi_get_reference_value(env, MyClass::es_constructor, &MyClass_constructor);\nassert(napi_ok == status);\nbool is_instance = false;\nstatus = napi_instanceof(env, es_this, MyClass_constructor, &is_instance);\nassert(napi_ok == status);\nif (is_instance) {\n  // napi_unwrap() ...\n} else {\n  // otherwise...\n}\n```\n\nThe reference must be freed once it is no longer needed.\n\nThere are occasions where `napi_instanceof()` is insufficient for ensuring that\na JavaScript object is a wrapper for a certain native type. This is the case\nespecially when wrapped JavaScript objects are passed back into the addon via\nstatic methods rather than as the `this` value of prototype methods. In such\ncases there is a chance that they may be unwrapped incorrectly.\n\n```js\nconst myAddon = require('./build/Release/my_addon.node');\n\n// `openDatabase()` returns a JavaScript object that wraps a native database\n// handle.\nconst dbHandle = myAddon.openDatabase();\n\n// `query()` returns a JavaScript object that wraps a native query handle.\nconst queryHandle = myAddon.query(dbHandle, 'Gimme ALL the things!');\n\n// There is an accidental error in the line below. The first parameter to\n// `myAddon.queryHasRecords()` should be the database handle (`dbHandle`), not\n// the query handle (`query`), so the correct condition for the while-loop\n// should be\n//\n// myAddon.queryHasRecords(dbHandle, queryHandle)\n//\nwhile (myAddon.queryHasRecords(queryHandle, dbHandle)) {\n  // retrieve records\n}\n```\n\nIn the above example `myAddon.queryHasRecords()` is a method that accepts two\narguments. The first is a database handle and the second is a query handle.\nInternally, it unwraps the first argument and casts the resulting pointer to a\nnative database handle. It then unwraps the second argument and casts the\nresulting pointer to a query handle. If the arguments are passed in the wrong\norder, the casts will work, however, there is a good chance that the underlying\ndatabase operation will fail, or will even cause an invalid memory access.\n\nTo ensure that the pointer retrieved from the first argument is indeed a pointer\nto a database handle and, similarly, that the pointer retrieved from the second\nargument is indeed a pointer to a query handle, the implementation of\n`queryHasRecords()` has to perform a type validation. Retaining the JavaScript\nclass constructor from which the database handle was instantiated and the\nconstructor from which the query handle was instantiated in `napi_ref`s can\nhelp, because `napi_instanceof()` can then be used to ensure that the instances\npassed into `queryHashRecords()` are indeed of the correct type.\n\nUnfortunately, `napi_instanceof()` does not protect against prototype\nmanipulation. For example, the prototype of the database handle instance can be\nset to the prototype of the constructor for query handle instances. In this\ncase, the database handle instance can appear as a query handle instance, and it\nwill pass the `napi_instanceof()` test for a query handle instance, while still\ncontaining a pointer to a database handle.\n\nTo this end, Node-API provides type-tagging capabilities.\n\nA type tag is a 128-bit integer unique to the addon. Node-API provides the\n`napi_type_tag` structure for storing a type tag. When such a value is passed\nalong with a JavaScript object or [external](#napi_create_external) stored in a `napi_value` to\n`napi_type_tag_object()`, the JavaScript object will be \"marked\" with the\ntype tag. The \"mark\" is invisible on the JavaScript side. When a JavaScript\nobject arrives into a native binding, `napi_check_object_type_tag()` can be used\nalong with the original type tag to determine whether the JavaScript object was\npreviously \"marked\" with the type tag. This creates a type-checking capability\nof a higher fidelity than `napi_instanceof()` can provide, because such type-\ntagging survives prototype manipulation and addon unloading/reloading.\n\nContinuing the above example, the following skeleton addon implementation\nillustrates the use of `napi_type_tag_object()` and\n`napi_check_object_type_tag()`.\n\n```c\n// This value is the type tag for a database handle. The command\n//\n//   uuidgen | sed -r -e 's/-//g' -e 's/(.{16})(.*)/0x\\1, 0x\\2/'\n//\n// can be used to obtain the two values with which to initialize the structure.\nstatic const napi_type_tag DatabaseHandleTypeTag = {\n  0x1edf75a38336451d, 0xa5ed9ce2e4c00c38\n};\n\n// This value is the type tag for a query handle.\nstatic const napi_type_tag QueryHandleTypeTag = {\n  0x9c73317f9fad44a3, 0x93c3920bf3b0ad6a\n};\n\nstatic napi_value\nopenDatabase(napi_env env, napi_callback_info info) {\n  napi_status status;\n  napi_value result;\n\n  // Perform the underlying action which results in a database handle.\n  DatabaseHandle* dbHandle = open_database();\n\n  // Create a new, empty JS object.\n  status = napi_create_object(env, &result);\n  if (status != napi_ok) return NULL;\n\n  // Tag the object to indicate that it holds a pointer to a `DatabaseHandle`.\n  status = napi_type_tag_object(env, result, &DatabaseHandleTypeTag);\n  if (status != napi_ok) return NULL;\n\n  // Store the pointer to the `DatabaseHandle` structure inside the JS object.\n  status = napi_wrap(env, result, dbHandle, NULL, NULL, NULL);\n  if (status != napi_ok) return NULL;\n\n  return result;\n}\n\n// Later when we receive a JavaScript object purporting to be a database handle\n// we can use `napi_check_object_type_tag()` to ensure that it is indeed such a\n// handle.\n\nstatic napi_value\nquery(napi_env env, napi_callback_info info) {\n  napi_status status;\n  size_t argc = 2;\n  napi_value argv[2];\n  bool is_db_handle;\n\n  status = napi_get_cb_info(env, info, &argc, argv, NULL, NULL);\n  if (status != napi_ok) return NULL;\n\n  // Check that the object passed as the first parameter has the previously\n  // applied tag.\n  status = napi_check_object_type_tag(env,\n                                      argv[0],\n                                      &DatabaseHandleTypeTag,\n                                      &is_db_handle);\n  if (status != napi_ok) return NULL;\n\n  // Throw a `TypeError` if it doesn't.\n  if (!is_db_handle) {\n    // Throw a TypeError.\n    return NULL;\n  }\n}\n```","summary":"Node-API offers a way to \"wrap\" C++ classes and instances so that the class constructor and methods can be called from JavaScript.","examples":[{"language":"c","displayName":null,"code":"napi_value MyClass_constructor = NULL;\nstatus = napi_get_reference_value(env, MyClass::es_constructor, &MyClass_constructor);\nassert(napi_ok == status);\nbool is_instance = false;\nstatus = napi_instanceof(env, es_this, MyClass_constructor, &is_instance);\nassert(napi_ok == status);\nif (is_instance) {\n  // napi_unwrap() ...\n} else {\n  // otherwise...\n}"},{"language":"js","displayName":null,"code":"const myAddon = require('./build/Release/my_addon.node');\n\n// `openDatabase()` returns a JavaScript object that wraps a native database\n// handle.\nconst dbHandle = myAddon.openDatabase();\n\n// `query()` returns a JavaScript object that wraps a native query handle.\nconst queryHandle = myAddon.query(dbHandle, 'Gimme ALL the things!');\n\n// There is an accidental error in the line below. The first parameter to\n// `myAddon.queryHasRecords()` should be the database handle (`dbHandle`), not\n// the query handle (`query`), so the correct condition for the while-loop\n// should be\n//\n// myAddon.queryHasRecords(dbHandle, queryHandle)\n//\nwhile (myAddon.queryHasRecords(queryHandle, dbHandle)) {\n  // retrieve records\n}"},{"language":"c","displayName":null,"code":"// This value is the type tag for a database handle. The command\n//\n//   uuidgen | sed -r -e 's/-//g' -e 's/(.{16})(.*)/0x\\1, 0x\\2/'\n//\n// can be used to obtain the two values with which to initialize the structure.\nstatic const napi_type_tag DatabaseHandleTypeTag = {\n  0x1edf75a38336451d, 0xa5ed9ce2e4c00c38\n};\n\n// This value is the type tag for a query handle.\nstatic const napi_type_tag QueryHandleTypeTag = {\n  0x9c73317f9fad44a3, 0x93c3920bf3b0ad6a\n};\n\nstatic napi_value\nopenDatabase(napi_env env, napi_callback_info info) {\n  napi_status status;\n  napi_value result;\n\n  // Perform the underlying action which results in a database handle.\n  DatabaseHandle* dbHandle = open_database();\n\n  // Create a new, empty JS object.\n  status = napi_create_object(env, &result);\n  if (status != napi_ok) return NULL;\n\n  // Tag the object to indicate that it holds a pointer to a `DatabaseHandle`.\n  status = napi_type_tag_object(env, result, &DatabaseHandleTypeTag);\n  if (status != napi_ok) return NULL;\n\n  // Store the pointer to the `DatabaseHandle` structure inside the JS object.\n  status = napi_wrap(env, result, dbHandle, NULL, NULL, NULL);\n  if (status != napi_ok) return NULL;\n\n  return result;\n}\n\n// Later when we receive a JavaScript object purporting to be a database handle\n// we can use `napi_check_object_type_tag()` to ensure that it is indeed such a\n// handle.\n\nstatic napi_value\nquery(napi_env env, napi_callback_info info) {\n  napi_status status;\n  size_t argc = 2;\n  napi_value argv[2];\n  bool is_db_handle;\n\n  status = napi_get_cb_info(env, info, &argc, argv, NULL, NULL);\n  if (status != napi_ok) return NULL;\n\n  // Check that the object passed as the first parameter has the previously\n  // applied tag.\n  status = napi_check_object_type_tag(env,\n                                      argv[0],\n                                      &DatabaseHandleTypeTag,\n                                      &is_db_handle);\n  if (status != napi_ok) return NULL;\n\n  // Throw a `TypeError` if it doesn't.\n  if (!is_db_handle) {\n    // Throw a TypeError.\n    return NULL;\n  }\n}"}],"children":[{"kind":"section","id":"napi_define_class","name":"napi_define_class","title":"`napi_define_class`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_define_class(napi_env env,\n                              const char* utf8name,\n                              size_t length,\n                              napi_callback constructor,\n                              void* data,\n                              size_t property_count,\n                              const napi_property_descriptor* properties,\n                              napi_value* result);\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] utf8name`: Name of the JavaScript constructor function. For clarity,\n  it is recommended to use the C++ class name when wrapping a C++ class.\n* `[in] length`: The length of the `utf8name` in bytes, or `NAPI_AUTO_LENGTH`\n  if it is null-terminated.\n* `[in] constructor`: Callback function that handles constructing instances\n  of the class. When wrapping a C++ class, this method must be a static member\n  with the [`napi_callback`](#napi_callback) signature. A C++ class constructor cannot be\n  used. [`napi_callback`](#napi_callback) provides more details.\n* `[in] data`: Optional data to be passed to the constructor callback as\n  the `data` property of the callback info.\n* `[in] property_count`: Number of items in the `properties` array argument.\n* `[in] properties`: Array of property descriptors describing static and\n  instance data properties, accessors, and methods on the class\n  See `napi_property_descriptor`.\n* `[out] result`: A `napi_value` representing the constructor function for\n  the class.\n\nReturns `napi_ok` if the API succeeded.\n\nDefines a JavaScript class, including:\n\n* A JavaScript constructor function that has the class name. When wrapping a\n  corresponding C++ class, the callback passed via `constructor` can be used to\n  instantiate a new C++ class instance, which can then be placed inside the\n  JavaScript object instance being constructed using [`napi_wrap`](#napi_wrap).\n* Properties on the constructor function whose implementation can call\n  corresponding *static* data properties, accessors, and methods of the C++\n  class (defined by property descriptors with the `napi_static` attribute).\n* Properties on the constructor function's `prototype` object. When wrapping a\n  C++ class, *non-static* data properties, accessors, and methods of the C++\n  class can be called from the static functions given in the property\n  descriptors without the `napi_static` attribute after retrieving the C++ class\n  instance placed inside the JavaScript object instance by using\n  [`napi_unwrap`](#napi_unwrap).\n\nWhen wrapping a C++ class, the C++ constructor callback passed via `constructor`\nshould be a static method on the class that calls the actual class constructor,\nthen wraps the new C++ instance in a JavaScript object, and returns the wrapper\nobject. See [`napi_wrap`](#napi_wrap) for details.\n\nThe JavaScript constructor function returned from [`napi_define_class`](#napi_define_class) is\noften saved and used later to construct new instances of the class from native\ncode, and/or to check whether provided values are instances of the class. In\nthat case, to prevent the function value from being garbage-collected, a\nstrong persistent reference to it can be created using\n[`napi_create_reference`](#napi_create_reference), ensuring that the reference count is kept >= 1.\n\nAny non-`NULL` data which is passed to this API via the `data` parameter or via\nthe `data` field of the `napi_property_descriptor` array items can be associated\nwith the resulting JavaScript constructor (which is returned in the `result`\nparameter) and freed whenever the class is garbage-collected by passing both\nthe JavaScript function and the data to [`napi_add_finalizer`](#napi_add_finalizer).","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_define_class(napi_env env,\n                              const char* utf8name,\n                              size_t length,\n                              napi_callback constructor,\n                              void* data,\n                              size_t property_count,\n                              const napi_property_descriptor* properties,\n                              napi_value* result);"}],"children":[]},{"kind":"section","id":"napi_wrap","name":"napi_wrap","title":"`napi_wrap`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_wrap(napi_env env,\n                      napi_value js_object,\n                      void* native_object,\n                      napi_finalize finalize_cb,\n                      void* finalize_hint,\n                      napi_ref* result);\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] js_object`: The JavaScript object that will be the wrapper for the\n  native object.\n* `[in] native_object`: The native instance that will be wrapped in the\n  JavaScript object.\n* `[in] finalize_cb`: Optional native callback that can be used to free the\n  native instance when the JavaScript object has been garbage-collected.\n  [`napi_finalize`](#napi_finalize) provides more details.\n* `[in] finalize_hint`: Optional contextual hint that is passed to the\n  finalize callback.\n* `[out] result`: Optional reference to the wrapped object.\n\nReturns `napi_ok` if the API succeeded.\n\nWraps a native instance in a JavaScript object. The native instance can be\nretrieved later using `napi_unwrap()`.\n\nWhen JavaScript code invokes a constructor for a class that was defined using\n`napi_define_class()`, the `napi_callback` for the constructor is invoked.\nAfter constructing an instance of the native class, the callback must then call\n`napi_wrap()` to wrap the newly constructed instance in the already-created\nJavaScript object that is the `this` argument to the constructor callback.\n(That `this` object was created from the constructor function's `prototype`,\nso it already has definitions of all the instance properties and methods.)\n\nTypically when wrapping a class instance, a finalize callback should be\nprovided that simply deletes the native instance that is received as the `data`\nargument to the finalize callback.\n\nThe optional returned reference is initially a weak reference, meaning it\nhas a reference count of 0. Typically this reference count would be incremented\ntemporarily during async operations that require the instance to remain valid.\n\n*Caution*: The optional returned reference (if obtained) should be deleted via\n[`napi_delete_reference`](#napi_delete_reference) ONLY in response to the finalize callback\ninvocation. If it is deleted before then, then the finalize callback may never\nbe invoked. Therefore, when obtaining a reference a finalize callback is also\nrequired in order to enable correct disposal of the reference.\n\nFinalizer callbacks may be deferred, leaving a window where the object has\nbeen garbage collected (and the weak reference is invalid) but the finalizer\nhasn't been called yet. When using `napi_get_reference_value()` on weak\nreferences returned by `napi_wrap()`, you should still handle an empty result.\n\nCalling `napi_wrap()` a second time on an object will return an error. To\nassociate another native instance with the object, use `napi_remove_wrap()`\nfirst.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_wrap(napi_env env,\n                      napi_value js_object,\n                      void* native_object,\n                      napi_finalize finalize_cb,\n                      void* finalize_hint,\n                      napi_ref* result);"}],"children":[]},{"kind":"section","id":"napi_unwrap","name":"napi_unwrap","title":"`napi_unwrap`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_unwrap(napi_env env,\n                        napi_value js_object,\n                        void** result);\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] js_object`: The object associated with the native instance.\n* `[out] result`: Pointer to the wrapped native instance.\n\nReturns `napi_ok` if the API succeeded.\n\nRetrieves a native instance that was previously wrapped in a JavaScript\nobject using `napi_wrap()`.\n\nWhen JavaScript code invokes a method or property accessor on the class, the\ncorresponding `napi_callback` is invoked. If the callback is for an instance\nmethod or accessor, then the `this` argument to the callback is the wrapper\nobject; the wrapped C++ instance that is the target of the call can be obtained\nthen by calling `napi_unwrap()` on the wrapper object.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_unwrap(napi_env env,\n                        napi_value js_object,\n                        void** result);"}],"children":[]},{"kind":"section","id":"napi_remove_wrap","name":"napi_remove_wrap","title":"`napi_remove_wrap`","scope":"module","overloadOf":null,"stability":null,"added":["v8.5.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_remove_wrap(napi_env env,\n                             napi_value js_object,\n                             void** result);\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] js_object`: The object associated with the native instance.\n* `[out] result`: Pointer to the wrapped native instance.\n\nReturns `napi_ok` if the API succeeded.\n\nRetrieves a native instance that was previously wrapped in the JavaScript\nobject `js_object` using `napi_wrap()` and removes the wrapping. If a finalize\ncallback was associated with the wrapping, it will no longer be called when the\nJavaScript object becomes garbage-collected.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_remove_wrap(napi_env env,\n                             napi_value js_object,\n                             void** result);"}],"children":[]},{"kind":"section","id":"napi_type_tag_object","name":"napi_type_tag_object","title":"`napi_type_tag_object`","scope":"module","overloadOf":null,"stability":null,"added":["v14.8.0","v12.19.0"],"deprecated":[],"removed":[],"napiVersion":[8],"changes":[],"description":"```c\nnapi_status napi_type_tag_object(napi_env env,\n                                 napi_value js_object,\n                                 const napi_type_tag* type_tag);\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] js_object`: The JavaScript object or [external](#napi_create_external) to be marked.\n* `[in] type_tag`: The tag with which the object is to be marked.\n\nReturns `napi_ok` if the API succeeded.\n\nAssociates the value of the `type_tag` pointer with the JavaScript object or\n[external](#napi_create_external). `napi_check_object_type_tag()` can then be used to compare the tag\nthat was attached to the object with one owned by the addon to ensure that the\nobject has the right type.\n\nIf the object already has an associated type tag, this API will return\n`napi_invalid_arg`.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_type_tag_object(napi_env env,\n                                 napi_value js_object,\n                                 const napi_type_tag* type_tag);"}],"children":[]},{"kind":"section","id":"napi_check_object_type_tag","name":"napi_check_object_type_tag","title":"`napi_check_object_type_tag`","scope":"module","overloadOf":null,"stability":null,"added":["v14.8.0","v12.19.0"],"deprecated":[],"removed":[],"napiVersion":[8],"changes":[],"description":"```c\nnapi_status napi_check_object_type_tag(napi_env env,\n                                       napi_value js_object,\n                                       const napi_type_tag* type_tag,\n                                       bool* result);\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] js_object`: The JavaScript object or [external](#napi_create_external) whose type tag to\n  examine.\n* `[in] type_tag`: The tag with which to compare any tag found on the object.\n* `[out] result`: Whether the type tag given matched the type tag on the\n  object. `false` is also returned if no type tag was found on the object.\n\nReturns `napi_ok` if the API succeeded.\n\nCompares the pointer given as `type_tag` with any that can be found on\n`js_object`. If no tag is found on `js_object` or, if a tag is found but it does\nnot match `type_tag`, then `result` is set to `false`. If a tag is found and it\nmatches `type_tag`, then `result` is set to `true`.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_check_object_type_tag(napi_env env,\n                                       napi_value js_object,\n                                       const napi_type_tag* type_tag,\n                                       bool* result);"}],"children":[]},{"kind":"section","id":"napi_add_finalizer","name":"napi_add_finalizer","title":"`napi_add_finalizer`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[5],"changes":[],"description":"```c\nnapi_status napi_add_finalizer(napi_env env,\n                               napi_value js_object,\n                               void* finalize_data,\n                               node_api_basic_finalize finalize_cb,\n                               void* finalize_hint,\n                               napi_ref* result);\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] js_object`: The JavaScript object to which the native data will be\n  attached.\n* `[in] finalize_data`: Optional data to be passed to `finalize_cb`.\n* `[in] finalize_cb`: Native callback that will be used to free the\n  native data when the JavaScript object has been garbage-collected.\n  [`napi_finalize`](#napi_finalize) provides more details.\n* `[in] finalize_hint`: Optional contextual hint that is passed to the\n  finalize callback.\n* `[out] result`: Optional reference to the JavaScript object.\n\nReturns `napi_ok` if the API succeeded.\n\nAdds a `napi_finalize` callback which will be called when the JavaScript object\nin `js_object` has been garbage-collected.\n\nThis API can be called multiple times on a single JavaScript object.\n\n*Caution*: The optional returned reference (if obtained) should be deleted via\n[`napi_delete_reference`](#napi_delete_reference) ONLY in response to the finalize callback\ninvocation. If it is deleted before then, then the finalize callback may never\nbe invoked. Therefore, when obtaining a reference a finalize callback is also\nrequired in order to enable correct disposal of the reference.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_add_finalizer(napi_env env,\n                               napi_value js_object,\n                               void* finalize_data,\n                               node_api_basic_finalize finalize_cb,\n                               void* finalize_hint,\n                               napi_ref* result);"}],"children":[{"kind":"section","id":"node_api_post_finalizer","name":"node_api_post_finalizer","title":"`node_api_post_finalizer`","scope":"module","overloadOf":null,"stability":{"index":"1","description":"Experimental"},"added":["v21.0.0","v20.10.0","v18.19.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"```c\nnapi_status node_api_post_finalizer(node_api_basic_env env,\n                                    napi_finalize finalize_cb,\n                                    void* finalize_data,\n                                    void* finalize_hint);\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] finalize_cb`: Native callback that will be used to free the\n  native data when the JavaScript object has been garbage-collected.\n  [`napi_finalize`](#napi_finalize) provides more details.\n* `[in] finalize_data`: Optional data to be passed to `finalize_cb`.\n* `[in] finalize_hint`: Optional contextual hint that is passed to the\n  finalize callback.\n\nReturns `napi_ok` if the API succeeded.\n\nSchedules a `napi_finalize` callback to be called asynchronously in the\nevent loop.\n\nNormally, finalizers are called while the GC (garbage collector) collects\nobjects. At that point calling any Node-API that may cause changes in the GC\nstate will be disabled and will crash Node.js.\n\n`node_api_post_finalizer` helps to work around this limitation by allowing the\nadd-on to defer calls to such Node-APIs to a point in time outside of the GC\nfinalization.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status node_api_post_finalizer(node_api_basic_env env,\n                                    napi_finalize finalize_cb,\n                                    void* finalize_data,\n                                    void* finalize_hint);"}],"children":[]}]}]},{"kind":"section","id":"simple-asynchronous-operations","name":"Simple asynchronous operations","title":"Simple asynchronous operations","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"Addon modules often need to leverage async helpers from libuv as part of their\nimplementation. This allows them to schedule work to be executed asynchronously\nso that their methods can return in advance of the work being completed. This\nallows them to avoid blocking overall execution of the Node.js application.\n\nNode-API provides an ABI-stable interface for these\nsupporting functions which covers the most common asynchronous use cases.\n\nNode-API defines the `napi_async_work` structure which is used to manage\nasynchronous workers. Instances are created/deleted with\n[`napi_create_async_work`](#napi_create_async_work) and [`napi_delete_async_work`](#napi_delete_async_work).\n\nThe `execute` and `complete` callbacks are functions that will be\ninvoked when the executor is ready to execute and when it completes its\ntask respectively.\n\nThe `execute` function should avoid making any Node-API calls\nthat could result in the execution of JavaScript or interaction with\nJavaScript objects. Most often, any code that needs to make Node-API\ncalls should be made in `complete` callback instead.\nAvoid using the `napi_env` parameter in the execute callback as\nit will likely execute JavaScript.\n\nThese functions implement the following interfaces:\n\n```c\ntypedef void (*napi_async_execute_callback)(napi_env env,\n                                            void* data);\ntypedef void (*napi_async_complete_callback)(napi_env env,\n                                             napi_status status,\n                                             void* data);\n```\n\nWhen these methods are invoked, the `data` parameter passed will be the\naddon-provided `void*` data that was passed into the\n`napi_create_async_work` call.\n\nOnce created the async worker can be queued\nfor execution using the [`napi_queue_async_work`](#napi_queue_async_work) function:\n\n```c\nnapi_status napi_queue_async_work(node_api_basic_env env,\n                                  napi_async_work work);\n```\n\n[`napi_cancel_async_work`](#napi_cancel_async_work) can be used if the work needs\nto be cancelled before the work has started execution.\n\nAfter calling [`napi_cancel_async_work`](#napi_cancel_async_work), the `complete` callback\nwill be invoked with a status value of `napi_cancelled`.\nThe work should not be deleted before the `complete`\ncallback invocation, even when it was cancelled.","summary":"Addon modules often need to leverage async helpers from libuv as part of their implementation. This allows them to schedule work to be executed asynchronously so that their methods can return in advance of the work being completed. This allows them to avoid blocking overall execution of the Node.js application.","examples":[{"language":"c","displayName":null,"code":"typedef void (*napi_async_execute_callback)(napi_env env,\n                                            void* data);\ntypedef void (*napi_async_complete_callback)(napi_env env,\n                                             napi_status status,\n                                             void* data);"},{"language":"c","displayName":null,"code":"napi_status napi_queue_async_work(node_api_basic_env env,\n                                  napi_async_work work);"}],"children":[{"kind":"section","id":"napi_create_async_work","name":"napi_create_async_work","title":"`napi_create_async_work`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[{"versions":["v8.6.0"],"prUrl":"https://github.com/nodejs/node/pull/14697","commit":null,"description":"Added `async_resource` and `async_resource_name` parameters."}],"description":"```c\nnapi_status napi_create_async_work(napi_env env,\n                                   napi_value async_resource,\n                                   napi_value async_resource_name,\n                                   napi_async_execute_callback execute,\n                                   napi_async_complete_callback complete,\n                                   void* data,\n                                   napi_async_work* result);\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] async_resource`: An optional object associated with the async work\n  that will be passed to possible `async_hooks` [`init` hooks](async_hooks.html#initasyncid-type-triggerasyncid-resource).\n* `[in] async_resource_name`: Identifier for the kind of resource that is being\n  provided for diagnostic information exposed by the `async_hooks` API.\n* `[in] execute`: The native function which should be called to execute the\n  logic asynchronously. The given function is called from a worker pool thread\n  and can execute in parallel with the main event loop thread.\n* `[in] complete`: The native function which will be called when the\n  asynchronous logic is completed or is cancelled. The given function is called\n  from the main event loop thread. [`napi_async_complete_callback`](#napi_async_complete_callback) provides\n  more details.\n* `[in] data`: User-provided data context. This will be passed back into the\n  execute and complete functions.\n* `[out] result`: `napi_async_work*` which is the handle to the newly created\n  async work.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API allocates a work object that is used to execute logic asynchronously.\nIt should be freed using [`napi_delete_async_work`](#napi_delete_async_work) once the work is no longer\nrequired.\n\n`async_resource_name` should be a null-terminated, UTF-8-encoded string.\n\nThe `async_resource_name` identifier is provided by the user and should be\nrepresentative of the type of async work being performed. It is also recommended\nto apply namespacing to the identifier, e.g. by including the module name. See\nthe [`async_hooks` documentation](async_hooks.html#type) for more information.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_create_async_work(napi_env env,\n                                   napi_value async_resource,\n                                   napi_value async_resource_name,\n                                   napi_async_execute_callback execute,\n                                   napi_async_complete_callback complete,\n                                   void* data,\n                                   napi_async_work* result);"}],"children":[]},{"kind":"section","id":"napi_delete_async_work","name":"napi_delete_async_work","title":"`napi_delete_async_work`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_delete_async_work(napi_env env,\n                                   napi_async_work work);\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] work`: The handle returned by the call to `napi_create_async_work`.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API frees a previously allocated work object.\n\nThis API can be called even if there is a pending JavaScript exception.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_delete_async_work(napi_env env,\n                                   napi_async_work work);"}],"children":[]},{"kind":"section","id":"napi_queue_async_work","name":"napi_queue_async_work","title":"`napi_queue_async_work`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_queue_async_work(node_api_basic_env env,\n                                  napi_async_work work);\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] work`: The handle returned by the call to `napi_create_async_work`.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API requests that the previously allocated work be scheduled\nfor execution. Once it returns successfully, this API must not be called again\nwith the same `napi_async_work` item or the result will be undefined.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_queue_async_work(node_api_basic_env env,\n                                  napi_async_work work);"}],"children":[]},{"kind":"section","id":"napi_cancel_async_work","name":"napi_cancel_async_work","title":"`napi_cancel_async_work`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_cancel_async_work(node_api_basic_env env,\n                                   napi_async_work work);\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] work`: The handle returned by the call to `napi_create_async_work`.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API cancels queued work if it has not yet\nbeen started. If it has already started executing, it cannot be\ncancelled and `napi_generic_failure` will be returned. If successful,\nthe `complete` callback will be invoked with a status value of\n`napi_cancelled`. The work should not be deleted before the `complete`\ncallback invocation, even if it has been successfully cancelled.\n\nThis API can be called even if there is a pending JavaScript exception.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_cancel_async_work(node_api_basic_env env,\n                                   napi_async_work work);"}],"children":[]}]},{"kind":"section","id":"custom-asynchronous-operations","name":"Custom asynchronous operations","title":"Custom asynchronous operations","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"The simple asynchronous work APIs above may not be appropriate for every\nscenario. When using any other asynchronous mechanism, the following APIs\nare necessary to ensure an asynchronous operation is properly tracked by\nthe runtime.","summary":"The simple asynchronous work APIs above may not be appropriate for every scenario. When using any other asynchronous mechanism, the following APIs are necessary to ensure an asynchronous operation is properly tracked by the runtime.","examples":[],"children":[{"kind":"section","id":"napi_async_init","name":"napi_async_init","title":"`napi_async_init`","scope":"module","overloadOf":null,"stability":null,"added":["v8.6.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[{"versions":["v25.0.0"],"prUrl":"https://github.com/nodejs/node/pull/59828","commit":null,"description":"The `async_resource` object will now be held as a strong reference."}],"description":"```c\nnapi_status napi_async_init(napi_env env,\n                            napi_value async_resource,\n                            napi_value async_resource_name,\n                            napi_async_context* result)\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] async_resource`: Object associated with the async work\n  that will be passed to possible `async_hooks` [`init` hooks](async_hooks.html#initasyncid-type-triggerasyncid-resource) and can be\n  accessed by [`async_hooks.executionAsyncResource()`](async_hooks.html#async_hooksexecutionasyncresource).\n* `[in] async_resource_name`: Identifier for the kind of resource that is being\n  provided for diagnostic information exposed by the `async_hooks` API.\n* `[out] result`: The initialized async context.\n\nReturns `napi_ok` if the API succeeded.\n\nIn order to retain ABI compatibility with previous versions, passing `NULL`\nfor `async_resource` does not result in an error. However, this is not\nrecommended as this will result in undesirable behavior with  `async_hooks`\n[`init` hooks](async_hooks.html#initasyncid-type-triggerasyncid-resource) and `async_hooks.executionAsyncResource()` as the resource is\nnow required by the underlying `async_hooks` implementation in order to provide\nthe linkage between async callbacks.\n\nPrevious versions of this API were not maintaining a strong reference to\n`async_resource` while the `napi_async_context` object existed and instead\nexpected the caller to hold a strong reference. This has been changed, as a\ncorresponding call to [`napi_async_destroy`](#napi_async_destroy) for every call to\n`napi_async_init()` is a requirement in any case to avoid memory leaks.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_async_init(napi_env env,\n                            napi_value async_resource,\n                            napi_value async_resource_name,\n                            napi_async_context* result)"}],"children":[]},{"kind":"section","id":"napi_async_destroy","name":"napi_async_destroy","title":"`napi_async_destroy`","scope":"module","overloadOf":null,"stability":null,"added":["v8.6.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_async_destroy(napi_env env,\n                               napi_async_context async_context);\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] async_context`: The async context to be destroyed.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API can be called even if there is a pending JavaScript exception.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_async_destroy(napi_env env,\n                               napi_async_context async_context);"}],"children":[]},{"kind":"section","id":"napi_make_callback","name":"napi_make_callback","title":"`napi_make_callback`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[{"versions":["v8.6.0"],"prUrl":"https://github.com/nodejs/node/pull/15189","commit":null,"description":"Added `async_context` parameter."}],"description":"```c\nNAPI_EXTERN napi_status napi_make_callback(napi_env env,\n                                           napi_async_context async_context,\n                                           napi_value recv,\n                                           napi_value func,\n                                           size_t argc,\n                                           const napi_value* argv,\n                                           napi_value* result);\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] async_context`: Context for the async operation that is\n  invoking the callback. This should normally be a value previously\n  obtained from [`napi_async_init`](#napi_async_init).\n  In order to retain ABI compatibility with previous versions, passing `NULL`\n  for `async_context` does not result in an error. However, this results\n  in incorrect operation of async hooks. Potential issues include loss of\n  async context when using the `AsyncLocalStorage` API.\n* `[in] recv`: The `this` value passed to the called function.\n* `[in] func`: `napi_value` representing the JavaScript function to be invoked.\n* `[in] argc`: The count of elements in the `argv` array.\n* `[in] argv`: Array of JavaScript values as `napi_value` representing the\n  arguments to the function. If `argc` is zero this parameter may be\n  omitted by passing in `NULL`.\n* `[out] result`: `napi_value` representing the JavaScript object returned.\n\nReturns `napi_ok` if the API succeeded.\n\nThis method allows a JavaScript function object to be called from a native\nadd-on. This API is similar to `napi_call_function`. However, it is used to call\n*from* native code back *into* JavaScript *after* returning from an async\noperation (when there is no other script on the stack). It is a fairly simple\nwrapper around `node::MakeCallback`.\n\nNote it is *not* necessary to use `napi_make_callback` from within a\n`napi_async_complete_callback`; in that situation the callback's async\ncontext has already been set up, so a direct call to `napi_call_function`\nis sufficient and appropriate. Use of the `napi_make_callback` function\nmay be required when implementing custom async behavior that does not use\n`napi_create_async_work`.\n\nAny `process.nextTick`s or Promises scheduled on the microtask queue by\nJavaScript during the callback are ran before returning back to C/C++.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"NAPI_EXTERN napi_status napi_make_callback(napi_env env,\n                                           napi_async_context async_context,\n                                           napi_value recv,\n                                           napi_value func,\n                                           size_t argc,\n                                           const napi_value* argv,\n                                           napi_value* result);"}],"children":[]},{"kind":"section","id":"napi_open_callback_scope","name":"napi_open_callback_scope","title":"`napi_open_callback_scope`","scope":"module","overloadOf":null,"stability":null,"added":["v9.6.0"],"deprecated":[],"removed":[],"napiVersion":[3],"changes":[],"description":"```c\nNAPI_EXTERN napi_status napi_open_callback_scope(napi_env env,\n                                                 napi_value resource_object,\n                                                 napi_async_context context,\n                                                 napi_callback_scope* result)\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] resource_object`: An object associated with the async work\n  that will be passed to possible `async_hooks` [`init` hooks](async_hooks.html#initasyncid-type-triggerasyncid-resource). This\n  parameter has been deprecated and is ignored at runtime. Use the\n  `async_resource` parameter in [`napi_async_init`](#napi_async_init) instead.\n* `[in] context`: Context for the async operation that is invoking the callback.\n  This should be a value previously obtained from [`napi_async_init`](#napi_async_init).\n* `[out] result`: The newly created scope.\n\nThere are cases (for example, resolving promises) where it is\nnecessary to have the equivalent of the scope associated with a callback\nin place when making certain Node-API calls. If there is no other script on\nthe stack the [`napi_open_callback_scope`](#napi_open_callback_scope) and\n[`napi_close_callback_scope`](#napi_close_callback_scope) functions can be used to open/close\nthe required scope.","summary":"There are cases (for example, resolving promises) where it is necessary to have the equivalent of the scope associated with a callback in place when making certain Node-API calls. If there is no other script on the stack the `napi_open_callback_scope` and `napi_close_callback_scope` functions can be used to open/close the required scope.","examples":[{"language":"c","displayName":null,"code":"NAPI_EXTERN napi_status napi_open_callback_scope(napi_env env,\n                                                 napi_value resource_object,\n                                                 napi_async_context context,\n                                                 napi_callback_scope* result)"}],"children":[]},{"kind":"section","id":"napi_close_callback_scope","name":"napi_close_callback_scope","title":"`napi_close_callback_scope`","scope":"module","overloadOf":null,"stability":null,"added":["v9.6.0"],"deprecated":[],"removed":[],"napiVersion":[3],"changes":[],"description":"```c\nNAPI_EXTERN napi_status napi_close_callback_scope(napi_env env,\n                                                  napi_callback_scope scope)\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] scope`: The scope to be closed.\n\nThis API can be called even if there is a pending JavaScript exception.","summary":"This API can be called even if there is a pending JavaScript exception.","examples":[{"language":"c","displayName":null,"code":"NAPI_EXTERN napi_status napi_close_callback_scope(napi_env env,\n                                                  napi_callback_scope scope)"}],"children":[]}]},{"kind":"section","id":"version-management","name":"Version management","title":"Version management","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"","summary":"","examples":[],"children":[{"kind":"section","id":"napi_get_node_version","name":"napi_get_node_version","title":"`napi_get_node_version`","scope":"module","overloadOf":null,"stability":null,"added":["v8.4.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\ntypedef struct {\n  uint32_t major;\n  uint32_t minor;\n  uint32_t patch;\n  const char* release;\n} napi_node_version;\n\nnapi_status napi_get_node_version(node_api_basic_env env,\n                                  const napi_node_version** version);\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[out] version`: A pointer to version information for Node.js itself.\n\nReturns `napi_ok` if the API succeeded.\n\nThis function fills the `version` struct with the major, minor, and patch\nversion of Node.js that is currently running, and the `release` field with the\nvalue of [`process.release.name`](process.html#processrelease).\n\nThe returned buffer is statically allocated and does not need to be freed.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"typedef struct {\n  uint32_t major;\n  uint32_t minor;\n  uint32_t patch;\n  const char* release;\n} napi_node_version;\n\nnapi_status napi_get_node_version(node_api_basic_env env,\n                                  const napi_node_version** version);"}],"children":[]},{"kind":"section","id":"napi_get_version","name":"napi_get_version","title":"`napi_get_version`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_get_version(node_api_basic_env env,\n                             uint32_t* result);\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[out] result`: The highest version of Node-API supported.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API returns the highest Node-API version supported by the\nNode.js runtime. Node-API is planned to be additive such that\nnewer releases of Node.js may support additional API functions.\nIn order to allow an addon to use a newer function when running with\nversions of Node.js that support it, while providing\nfallback behavior when running with Node.js versions that don't\nsupport it:\n\n* Call `napi_get_version()` to determine if the API is available.\n* If available, dynamically load a pointer to the function using `uv_dlsym()`.\n* Use the dynamically loaded pointer to invoke the function.\n* If the function is not available, provide an alternate implementation\n  that does not use the function.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_get_version(node_api_basic_env env,\n                             uint32_t* result);"}],"children":[]}]},{"kind":"section","id":"memory-management","name":"Memory management","title":"Memory management","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"","summary":"","examples":[],"children":[{"kind":"section","id":"napi_adjust_external_memory","name":"napi_adjust_external_memory","title":"`napi_adjust_external_memory`","scope":"module","overloadOf":null,"stability":null,"added":["v8.5.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nNAPI_EXTERN napi_status napi_adjust_external_memory(node_api_basic_env env,\n                                                    int64_t change_in_bytes,\n                                                    int64_t* result);\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] change_in_bytes`: The change in externally allocated memory that is kept\n  alive by JavaScript objects.\n* `[out] result`: The adjusted value. This value should reflect the\n  total amount of external memory with the given `change_in_bytes` included.\n  The absolute value of the returned value should not  be depended on.\n  For example, implementations may use a single counter for all addons, or a\n  counter for each addon.\n\nReturns `napi_ok` if the API succeeded.\n\nThis function gives the runtime an indication of the amount of externally\nallocated memory that is kept alive by JavaScript objects\n(i.e. a JavaScript object that points to its own memory allocated by a\nnative addon). Registering externally allocated memory may, but is not\nguaranteed to, trigger global garbage collections more\noften than it would otherwise.\n\nThis function is expected to be called in a manner such that an\naddon does not decrease the external memory more than it has\nincreased the external memory.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"NAPI_EXTERN napi_status napi_adjust_external_memory(node_api_basic_env env,\n                                                    int64_t change_in_bytes,\n                                                    int64_t* result);"}],"children":[]}]},{"kind":"section","id":"promises","name":"Promises","title":"Promises","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"Node-API provides facilities for creating `Promise` objects as described in\n[Section Promise objects](https://tc39.es/ecma262/#sec-promise-objects) of the ECMA specification. It implements promises as a pair of\nobjects. When a promise is created by `napi_create_promise()`, a \"deferred\"\nobject is created and returned alongside the `Promise`. The deferred object is\nbound to the created `Promise` and is the only means to resolve or reject the\n`Promise` using `napi_resolve_deferred()` or `napi_reject_deferred()`. The\ndeferred object that is created by `napi_create_promise()` is freed by\n`napi_resolve_deferred()` or `napi_reject_deferred()`. The `Promise` object may\nbe returned to JavaScript where it can be used in the usual fashion.\n\nFor example, to create a promise and pass it to an asynchronous worker:\n\n```c\nnapi_deferred deferred;\nnapi_value promise;\nnapi_status status;\n\n// Create the promise.\nstatus = napi_create_promise(env, &deferred, &promise);\nif (status != napi_ok) return NULL;\n\n// Pass the deferred to a function that performs an asynchronous action.\ndo_something_asynchronous(deferred);\n\n// Return the promise to JS\nreturn promise;\n```\n\nThe above function `do_something_asynchronous()` would perform its asynchronous\naction and then it would resolve or reject the deferred, thereby concluding the\npromise and freeing the deferred:\n\n```c\nnapi_deferred deferred;\nnapi_value undefined;\nnapi_status status;\n\n// Create a value with which to conclude the deferred.\nstatus = napi_get_undefined(env, &undefined);\nif (status != napi_ok) return NULL;\n\n// Resolve or reject the promise associated with the deferred depending on\n// whether the asynchronous action succeeded.\nif (asynchronous_action_succeeded) {\n  status = napi_resolve_deferred(env, deferred, undefined);\n} else {\n  status = napi_reject_deferred(env, deferred, undefined);\n}\nif (status != napi_ok) return NULL;\n\n// At this point the deferred has been freed, so we should assign NULL to it.\ndeferred = NULL;\n```","summary":"Node-API provides facilities for creating `Promise` objects as described in Section Promise objects of the ECMA specification. It implements promises as a pair of objects. When a promise is created by `napi_create_promise()`, a \"deferred\" object is created and returned alongside the `Promise`. The deferred object is bound to the created `Promise` and is the only means to resolve or reject the `Promise` using `napi_resolve_deferred()` or `napi_reject_deferred()`. The deferred object that is created by `napi_create_promise()` is freed by `napi_resolve_deferred()` or `napi_reject_deferred()`. The `Promise` object may be returned to JavaScript where it can be used in the usual fashion.","examples":[{"language":"c","displayName":null,"code":"napi_deferred deferred;\nnapi_value promise;\nnapi_status status;\n\n// Create the promise.\nstatus = napi_create_promise(env, &deferred, &promise);\nif (status != napi_ok) return NULL;\n\n// Pass the deferred to a function that performs an asynchronous action.\ndo_something_asynchronous(deferred);\n\n// Return the promise to JS\nreturn promise;"},{"language":"c","displayName":null,"code":"napi_deferred deferred;\nnapi_value undefined;\nnapi_status status;\n\n// Create a value with which to conclude the deferred.\nstatus = napi_get_undefined(env, &undefined);\nif (status != napi_ok) return NULL;\n\n// Resolve or reject the promise associated with the deferred depending on\n// whether the asynchronous action succeeded.\nif (asynchronous_action_succeeded) {\n  status = napi_resolve_deferred(env, deferred, undefined);\n} else {\n  status = napi_reject_deferred(env, deferred, undefined);\n}\nif (status != napi_ok) return NULL;\n\n// At this point the deferred has been freed, so we should assign NULL to it.\ndeferred = NULL;"}],"children":[{"kind":"section","id":"napi_create_promise","name":"napi_create_promise","title":"`napi_create_promise`","scope":"module","overloadOf":null,"stability":null,"added":["v8.5.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_create_promise(napi_env env,\n                                napi_deferred* deferred,\n                                napi_value* promise);\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[out] deferred`: A newly created deferred object which can later be passed to\n  `napi_resolve_deferred()` or `napi_reject_deferred()` to resolve resp. reject\n  the associated promise.\n* `[out] promise`: The JavaScript promise associated with the deferred object.\n\nReturns `napi_ok` if the API succeeded.\n\nThis API creates a deferred object and a JavaScript promise.","summary":"Returns `napi_ok` if the API succeeded.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_create_promise(napi_env env,\n                                napi_deferred* deferred,\n                                napi_value* promise);"}],"children":[]},{"kind":"section","id":"napi_resolve_deferred","name":"napi_resolve_deferred","title":"`napi_resolve_deferred`","scope":"module","overloadOf":null,"stability":null,"added":["v8.5.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_resolve_deferred(napi_env env,\n                                  napi_deferred deferred,\n                                  napi_value resolution);\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] deferred`: The deferred object whose associated promise to resolve.\n* `[in] resolution`: The value with which to resolve the promise.\n\nThis API resolves a JavaScript promise by way of the deferred object\nwith which it is associated. Thus, it can only be used to resolve JavaScript\npromises for which the corresponding deferred object is available. This\neffectively means that the promise must have been created using\n`napi_create_promise()` and the deferred object returned from that call must\nhave been retained in order to be passed to this API.\n\nThe deferred object is freed upon successful completion.","summary":"This API resolves a JavaScript promise by way of the deferred object with which it is associated. Thus, it can only be used to resolve JavaScript promises for which the corresponding deferred object is available. This effectively means that the promise must have been created using `napi_create_promise()` and the deferred object returned from that call must have been retained in order to be passed to this API.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_resolve_deferred(napi_env env,\n                                  napi_deferred deferred,\n                                  napi_value resolution);"}],"children":[]},{"kind":"section","id":"napi_reject_deferred","name":"napi_reject_deferred","title":"`napi_reject_deferred`","scope":"module","overloadOf":null,"stability":null,"added":["v8.5.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_reject_deferred(napi_env env,\n                                 napi_deferred deferred,\n                                 napi_value rejection);\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] deferred`: The deferred object whose associated promise to resolve.\n* `[in] rejection`: The value with which to reject the promise.\n\nThis API rejects a JavaScript promise by way of the deferred object\nwith which it is associated. Thus, it can only be used to reject JavaScript\npromises for which the corresponding deferred object is available. This\neffectively means that the promise must have been created using\n`napi_create_promise()` and the deferred object returned from that call must\nhave been retained in order to be passed to this API.\n\nThe deferred object is freed upon successful completion.","summary":"This API rejects a JavaScript promise by way of the deferred object with which it is associated. Thus, it can only be used to reject JavaScript promises for which the corresponding deferred object is available. This effectively means that the promise must have been created using `napi_create_promise()` and the deferred object returned from that call must have been retained in order to be passed to this API.","examples":[{"language":"c","displayName":null,"code":"napi_status napi_reject_deferred(napi_env env,\n                                 napi_deferred deferred,\n                                 napi_value rejection);"}],"children":[]},{"kind":"section","id":"napi_is_promise","name":"napi_is_promise","title":"`napi_is_promise`","scope":"module","overloadOf":null,"stability":null,"added":["v8.5.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nnapi_status napi_is_promise(napi_env env,\n                            napi_value value,\n                            bool* is_promise);\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] value`: The value to examine\n* `[out] is_promise`: Flag indicating whether `promise` is a native promise\n  object (that is, a promise object created by the underlying engine).","summary":"","examples":[{"language":"c","displayName":null,"code":"napi_status napi_is_promise(napi_env env,\n                            napi_value value,\n                            bool* is_promise);"}],"children":[]}]},{"kind":"section","id":"script-execution","name":"Script execution","title":"Script execution","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"Node-API provides an API for executing a string containing JavaScript using the\nunderlying JavaScript engine.","summary":"Node-API provides an API for executing a string containing JavaScript using the underlying JavaScript engine.","examples":[],"children":[{"kind":"section","id":"napi_run_script","name":"napi_run_script","title":"`napi_run_script`","scope":"module","overloadOf":null,"stability":null,"added":["v8.5.0"],"deprecated":[],"removed":[],"napiVersion":[1],"changes":[],"description":"```c\nNAPI_EXTERN napi_status napi_run_script(napi_env env,\n                                        napi_value script,\n                                        napi_value* result);\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] script`: A JavaScript string containing the script to execute.\n* `[out] result`: The value resulting from having executed the script.\n\nThis function executes a string of JavaScript code and returns its result with\nthe following caveats:\n\n* Unlike `eval`, this function does not allow the script to access the current\n  lexical scope, and therefore also does not allow to access the\n  [module scope](modules.html#the-module-scope), meaning that pseudo-globals such as `require` will not be\n  available.\n* The script can access the [global scope](globals.html). Function and `var` declarations\n  in the script will be added to the [`global`](globals.html#global) object. Variable declarations\n  made using `let` and `const` will be visible globally, but will not be added\n  to the [`global`](globals.html#global) object.\n* The value of `this` is [`global`](globals.html#global) within the script.","summary":"This function executes a string of JavaScript code and returns its result with the following caveats:","examples":[{"language":"c","displayName":null,"code":"NAPI_EXTERN napi_status napi_run_script(napi_env env,\n                                        napi_value script,\n                                        napi_value* result);"}],"children":[]}]},{"kind":"section","id":"libuv-event-loop","name":"libuv event loop","title":"libuv event loop","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"Node-API provides a function for getting the current event loop associated with\na specific `napi_env`.","summary":"Node-API provides a function for getting the current event loop associated with a specific `napi_env`.","examples":[],"children":[{"kind":"section","id":"napi_get_uv_event_loop","name":"napi_get_uv_event_loop","title":"`napi_get_uv_event_loop`","scope":"module","overloadOf":null,"stability":null,"added":["v9.3.0","v8.10.0"],"deprecated":[],"removed":[],"napiVersion":[2],"changes":[],"description":"```c\nNAPI_EXTERN napi_status napi_get_uv_event_loop(node_api_basic_env env,\n                                               struct uv_loop_s** loop);\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[out] loop`: The current libuv loop instance.\n\nNote: While libuv only [guarantees ABI stability](https://github.com/libuv/libuv?tab=readme-ov-file#versioning)\nin a major version, its use may result in an addon that does not work across\nNode.js major versions.\n\n[ThreadSafeFunction](#asynchronous-thread-safe-function-calls)\nis an ABI-stable alternative for many use cases to calling into the\nJavaScript thread from another thread.","summary":"Note: While libuv only guarantees ABI stability in a major version, its use may result in an addon that does not work across Node.js major versions.","examples":[{"language":"c","displayName":null,"code":"NAPI_EXTERN napi_status napi_get_uv_event_loop(node_api_basic_env env,\n                                               struct uv_loop_s** loop);"}],"children":[]}]},{"kind":"section","id":"asynchronous-thread-safe-function-calls","name":"Asynchronous thread-safe function calls","title":"Asynchronous thread-safe function calls","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"JavaScript functions can normally only be called from a native addon's main\nthread. If an addon creates additional threads, then Node-API functions that\nrequire a `napi_env`, `napi_value`, or `napi_ref` must not be called from those\nthreads.\n\nWhen an addon has additional threads and JavaScript functions need to be invoked\nbased on the processing completed by those threads, those threads must\ncommunicate with the addon's main thread so that the main thread can invoke the\nJavaScript function on their behalf. The thread-safe function APIs provide an\neasy way to do this.\n\nThese APIs provide the type `napi_threadsafe_function` as well as APIs to\ncreate, destroy, and call objects of this type.\n`napi_create_threadsafe_function()` creates a persistent reference to a\n`napi_value` that holds a JavaScript function which can be called from multiple\nthreads. The calls happen asynchronously. This means that values with which the\nJavaScript callback is to be called will be placed in a queue, and, for each\nvalue in the queue, a call will eventually be made to the JavaScript function.\n\nUpon creation of a `napi_threadsafe_function` a `napi_finalize` callback can be\nprovided. This callback will be invoked on the main thread when the thread-safe\nfunction is about to be destroyed. It receives the context and the finalize data\ngiven during construction, and provides an opportunity for cleaning up after the\nthreads e.g. by calling `uv_thread_join()`. **Aside from the main loop thread,\nno threads should be using the thread-safe function after the finalize callback\ncompletes.**\n\nThe `context` given during the call to `napi_create_threadsafe_function()` can\nbe retrieved from any thread with a call to\n`napi_get_threadsafe_function_context()`.","summary":"JavaScript functions can normally only be called from a native addon's main thread. If an addon creates additional threads, then Node-API functions that require a `napi_env`, `napi_value`, or `napi_ref` must not be called from those threads.","examples":[],"children":[{"kind":"section","id":"calling-a-thread-safe-function","name":"Calling a thread-safe function","title":"Calling a thread-safe function","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"`napi_call_threadsafe_function()` can be used for initiating a call into\nJavaScript. `napi_call_threadsafe_function()` accepts a parameter which controls\nwhether the API behaves blockingly. If set to `napi_tsfn_nonblocking`, the API\nbehaves non-blockingly, returning `napi_queue_full` if the queue was full,\npreventing data from being successfully added to the queue. If set to\n`napi_tsfn_blocking`, the API blocks until space becomes available in the queue.\n`napi_call_threadsafe_function()` never blocks if the thread-safe function was\ncreated with a maximum queue size of 0.\n\n`napi_call_threadsafe_function()` should not be called with `napi_tsfn_blocking`\nfrom a JavaScript thread, because, if the queue is full, it may cause the\nJavaScript thread to deadlock.\n\nThe actual call into JavaScript is controlled by the callback given via the\n`call_js_cb` parameter. `call_js_cb` is invoked on the main thread once for each\nvalue that was placed into the queue by a successful call to\n`napi_call_threadsafe_function()`. If such a callback is not given, a default\ncallback will be used, and the resulting JavaScript call will have no arguments.\nThe `call_js_cb` callback receives the JavaScript function to call as a\n`napi_value` in its parameters, as well as the `void*` context pointer used when\ncreating the `napi_threadsafe_function`, and the next data pointer that was\ncreated by one of the secondary threads. The callback can then use an API such\nas `napi_call_function()` to call into JavaScript.\n\nThe callback may also be invoked with `env` and `call_js_cb` both set to `NULL`\nto indicate that calls into JavaScript are no longer possible, while items\nremain in the queue that may need to be freed. This normally occurs when the\nNode.js process exits while there is a thread-safe function still active.\n\nIt is not necessary to call into JavaScript via `napi_make_callback()` because\nNode-API runs `call_js_cb` in a context appropriate for callbacks.\n\nZero or more queued items may be invoked in each tick of the event loop.\nApplications should not depend on a specific behavior other than progress in\ninvoking callbacks will be made and events will be invoked\nas time moves forward.","summary":"`napi_call_threadsafe_function()` can be used for initiating a call into JavaScript. `napi_call_threadsafe_function()` accepts a parameter which controls whether the API behaves blockingly. If set to `napi_tsfn_nonblocking`, the API behaves non-blockingly, returning `napi_queue_full` if the queue was full, preventing data from being successfully added to the queue. If set to `napi_tsfn_blocking`, the API blocks until space becomes available in the queue. `napi_call_threadsafe_function()` never blocks if the thread-safe function was created with a maximum queue size of 0.","examples":[],"children":[]},{"kind":"section","id":"reference-counting-of-thread-safe-functions","name":"Reference counting of thread-safe functions","title":"Reference counting of thread-safe functions","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"Threads can be added to and removed from a `napi_threadsafe_function` object\nduring its existence. Thus, in addition to specifying an initial number of\nthreads upon creation, `napi_acquire_threadsafe_function` can be called to\nindicate that a new thread will start making use of the thread-safe function.\nSimilarly, `napi_release_threadsafe_function` can be called to indicate that an\nexisting thread will stop making use of the thread-safe function.\n\n`napi_threadsafe_function` objects are destroyed when every thread which uses\nthe object has called `napi_release_threadsafe_function()` or has received a\nreturn status of `napi_closing` in response to a call to\n`napi_call_threadsafe_function`. The queue is emptied before the\n`napi_threadsafe_function` is destroyed. `napi_release_threadsafe_function()`\nshould be the last API call made in conjunction with a given\n`napi_threadsafe_function`, because after the call completes, there is no\nguarantee that the `napi_threadsafe_function` is still allocated. For the same\nreason, do not use a thread-safe function\nafter receiving a return value of `napi_closing` in response to a call to\n`napi_call_threadsafe_function`. Data associated with the\n`napi_threadsafe_function` can be freed in its `napi_finalize` callback which\nwas passed to `napi_create_threadsafe_function()`. The parameter\n`initial_thread_count` of `napi_create_threadsafe_function` marks the initial\nnumber of acquisitions of the thread-safe functions, instead of calling\n`napi_acquire_threadsafe_function` multiple times at creation.\n\nOnce the number of threads making use of a `napi_threadsafe_function` reaches\nzero, no further threads can start making use of it by calling\n`napi_acquire_threadsafe_function()`. In fact, all subsequent API calls\nassociated with it, except `napi_release_threadsafe_function()`, will return an\nerror value of `napi_closing`.\n\nThe thread-safe function can be \"aborted\" by giving a value of `napi_tsfn_abort`\nto `napi_release_threadsafe_function()`. This will cause all subsequent APIs\nassociated with the thread-safe function except\n`napi_release_threadsafe_function()` to return `napi_closing` even before its\nreference count reaches zero. In particular, `napi_call_threadsafe_function()`\nwill return `napi_closing`, thus informing the threads that it is no longer\npossible to make asynchronous calls to the thread-safe function. This can be\nused as a criterion for terminating the thread. **Upon receiving a return value\nof `napi_closing` from `napi_call_threadsafe_function()` a thread must not use\nthe thread-safe function anymore because it is no longer guaranteed to\nbe allocated.**","summary":"Threads can be added to and removed from a `napi_threadsafe_function` object during its existence. Thus, in addition to specifying an initial number of threads upon creation, `napi_acquire_threadsafe_function` can be called to indicate that a new thread will start making use of the thread-safe function. Similarly, `napi_release_threadsafe_function` can be called to indicate that an existing thread will stop making use of the thread-safe function.","examples":[],"children":[]},{"kind":"section","id":"deciding-whether-to-keep-the-process-running","name":"Deciding whether to keep the process running","title":"Deciding whether to keep the process running","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"Similarly to libuv handles, thread-safe functions can be \"referenced\" and\n\"unreferenced\". A \"referenced\" thread-safe function will cause the event loop on\nthe thread on which it is created to remain alive until the thread-safe function\nis destroyed. In contrast, an \"unreferenced\" thread-safe function will not\nprevent the event loop from exiting. The APIs `napi_ref_threadsafe_function` and\n`napi_unref_threadsafe_function` exist for this purpose.\n\nNeither does `napi_unref_threadsafe_function` mark the thread-safe functions as\nable to be destroyed nor does `napi_ref_threadsafe_function` prevent it from\nbeing destroyed.","summary":"Similarly to libuv handles, thread-safe functions can be \"referenced\" and \"unreferenced\". A \"referenced\" thread-safe function will cause the event loop on the thread on which it is created to remain alive until the thread-safe function is destroyed. In contrast, an \"unreferenced\" thread-safe function will not prevent the event loop from exiting. The APIs `napi_ref_threadsafe_function` and `napi_unref_threadsafe_function` exist for this purpose.","examples":[],"children":[]},{"kind":"section","id":"napi_create_threadsafe_function","name":"napi_create_threadsafe_function","title":"`napi_create_threadsafe_function`","scope":"module","overloadOf":null,"stability":null,"added":["v10.6.0"],"deprecated":[],"removed":[],"napiVersion":[4],"changes":[{"versions":["v12.6.0","v10.17.0"],"prUrl":"https://github.com/nodejs/node/pull/27791","commit":null,"description":"Made `func` parameter optional with custom `call_js_cb`."}],"description":"```c\nNAPI_EXTERN napi_status\nnapi_create_threadsafe_function(napi_env env,\n                                napi_value func,\n                                napi_value async_resource,\n                                napi_value async_resource_name,\n                                size_t max_queue_size,\n                                size_t initial_thread_count,\n                                void* thread_finalize_data,\n                                napi_finalize thread_finalize_cb,\n                                void* context,\n                                napi_threadsafe_function_call_js call_js_cb,\n                                napi_threadsafe_function* result);\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] func`: An optional JavaScript function to call from another thread. It\n  must be provided if `NULL` is passed to `call_js_cb`.\n* `[in] async_resource`: An optional object associated with the async work that\n  will be passed to possible `async_hooks` [`init` hooks](async_hooks.html#initasyncid-type-triggerasyncid-resource).\n* `[in] async_resource_name`: A JavaScript string to provide an identifier for\n  the kind of resource that is being provided for diagnostic information exposed\n  by the `async_hooks` API.\n* `[in] max_queue_size`: Maximum size of the queue. `0` for no limit.\n* `[in] initial_thread_count`: The initial number of acquisitions, i.e. the\n  initial number of threads, including the main thread, which will be making use\n  of this function.\n* `[in] thread_finalize_data`: Optional data to be passed to `thread_finalize_cb`.\n* `[in] thread_finalize_cb`: Optional function to call when the\n  `napi_threadsafe_function` is being destroyed.\n* `[in] context`: Optional data to attach to the resulting\n  `napi_threadsafe_function`.\n* `[in] call_js_cb`: Optional callback which calls the JavaScript function in\n  response to a call on a different thread. This callback will be called on the\n  main thread. If not given, the JavaScript function will be called with no\n  parameters and with `undefined` as its `this` value.\n  [`napi_threadsafe_function_call_js`](#napi_threadsafe_function_call_js) provides more details.\n* `[out] result`: The asynchronous thread-safe JavaScript function.\n\n**Change History:**\n\n* Version 10 (`NAPI_VERSION` is defined as `10` or higher):\n\n  Uncaught exceptions thrown in `call_js_cb` are handled with the\n  [`'uncaughtException'`](process.html#event-uncaughtexception) event, instead of being ignored.","summary":"**Change History:**","examples":[{"language":"c","displayName":null,"code":"NAPI_EXTERN napi_status\nnapi_create_threadsafe_function(napi_env env,\n                                napi_value func,\n                                napi_value async_resource,\n                                napi_value async_resource_name,\n                                size_t max_queue_size,\n                                size_t initial_thread_count,\n                                void* thread_finalize_data,\n                                napi_finalize thread_finalize_cb,\n                                void* context,\n                                napi_threadsafe_function_call_js call_js_cb,\n                                napi_threadsafe_function* result);"}],"children":[]},{"kind":"section","id":"napi_get_threadsafe_function_context","name":"napi_get_threadsafe_function_context","title":"`napi_get_threadsafe_function_context`","scope":"module","overloadOf":null,"stability":null,"added":["v10.6.0"],"deprecated":[],"removed":[],"napiVersion":[4],"changes":[],"description":"```c\nNAPI_EXTERN napi_status\nnapi_get_threadsafe_function_context(napi_threadsafe_function func,\n                                     void** result);\n```\n\n* `[in] func`: The thread-safe function for which to retrieve the context.\n* `[out] result`: The location where to store the context.\n\nThis API may be called from any thread which makes use of `func`.","summary":"This API may be called from any thread which makes use of `func`.","examples":[{"language":"c","displayName":null,"code":"NAPI_EXTERN napi_status\nnapi_get_threadsafe_function_context(napi_threadsafe_function func,\n                                     void** result);"}],"children":[]},{"kind":"section","id":"napi_call_threadsafe_function","name":"napi_call_threadsafe_function","title":"`napi_call_threadsafe_function`","scope":"module","overloadOf":null,"stability":null,"added":["v10.6.0"],"deprecated":[],"removed":[],"napiVersion":[4],"changes":[{"versions":["v14.5.0"],"prUrl":"https://github.com/nodejs/node/pull/33453","commit":null,"description":"Support for `napi_would_deadlock` has been reverted."},{"versions":["v14.1.0"],"prUrl":"https://github.com/nodejs/node/pull/32689","commit":null,"description":"Return `napi_would_deadlock` when called with `napi_tsfn_blocking` from the main thread or a worker thread and the queue is full."}],"description":"```c\nNAPI_EXTERN napi_status\nnapi_call_threadsafe_function(napi_threadsafe_function func,\n                              void* data,\n                              napi_threadsafe_function_call_mode is_blocking);\n```\n\n* `[in] func`: The asynchronous thread-safe JavaScript function to invoke.\n* `[in] data`: Data to send into JavaScript via the callback `call_js_cb`\n  provided during the creation of the thread-safe JavaScript function.\n* `[in] is_blocking`: Flag whose value can be either `napi_tsfn_blocking` to\n  indicate that the call should block if the queue is full or\n  `napi_tsfn_nonblocking` to indicate that the call should return immediately\n  with a status of `napi_queue_full` whenever the queue is full.\n\nThis API should not be called with `napi_tsfn_blocking` from a JavaScript\nthread, because, if the queue is full, it may cause the JavaScript thread to\ndeadlock.\n\nThis API will return `napi_closing` if `napi_release_threadsafe_function()` was\ncalled with `abort` set to `napi_tsfn_abort` from any thread. The value is only\nadded to the queue if the API returns `napi_ok`.\n\nThis API may be called from any thread which makes use of `func`.","summary":"This API should not be called with `napi_tsfn_blocking` from a JavaScript thread, because, if the queue is full, it may cause the JavaScript thread to deadlock.","examples":[{"language":"c","displayName":null,"code":"NAPI_EXTERN napi_status\nnapi_call_threadsafe_function(napi_threadsafe_function func,\n                              void* data,\n                              napi_threadsafe_function_call_mode is_blocking);"}],"children":[]},{"kind":"section","id":"napi_acquire_threadsafe_function","name":"napi_acquire_threadsafe_function","title":"`napi_acquire_threadsafe_function`","scope":"module","overloadOf":null,"stability":null,"added":["v10.6.0"],"deprecated":[],"removed":[],"napiVersion":[4],"changes":[],"description":"```c\nNAPI_EXTERN napi_status\nnapi_acquire_threadsafe_function(napi_threadsafe_function func);\n```\n\n* `[in] func`: The asynchronous thread-safe JavaScript function to start making\n  use of.\n\nA thread should call this API before passing `func` to any other thread-safe\nfunction APIs to indicate that it will be making use of `func`. This prevents\n`func` from being destroyed when all other threads have stopped making use of\nit.\n\nThis API may be called from any thread which will start making use of `func`.","summary":"A thread should call this API before passing `func` to any other thread-safe function APIs to indicate that it will be making use of `func`. This prevents `func` from being destroyed when all other threads have stopped making use of it.","examples":[{"language":"c","displayName":null,"code":"NAPI_EXTERN napi_status\nnapi_acquire_threadsafe_function(napi_threadsafe_function func);"}],"children":[]},{"kind":"section","id":"napi_release_threadsafe_function","name":"napi_release_threadsafe_function","title":"`napi_release_threadsafe_function`","scope":"module","overloadOf":null,"stability":null,"added":["v10.6.0"],"deprecated":[],"removed":[],"napiVersion":[4],"changes":[],"description":"```c\nNAPI_EXTERN napi_status\nnapi_release_threadsafe_function(napi_threadsafe_function func,\n                                 napi_threadsafe_function_release_mode mode);\n```\n\n* `[in] func`: The asynchronous thread-safe JavaScript function whose reference\n  count to decrement.\n* `[in] mode`: Flag whose value can be either `napi_tsfn_release` to indicate\n  that the current thread will make no further calls to the thread-safe\n  function, or `napi_tsfn_abort` to indicate that in addition to the current\n  thread, no other thread should make any further calls to the thread-safe\n  function. If set to `napi_tsfn_abort`, further calls to\n  `napi_call_threadsafe_function()` will return `napi_closing`, and no further\n  values will be placed in the queue.\n\nA thread should call this API when it stops making use of `func`. Passing `func`\nto any thread-safe APIs after having called this API has undefined results, as\n`func` may have been destroyed.\n\nThis API may be called from any thread which will stop making use of `func`.","summary":"A thread should call this API when it stops making use of `func`. Passing `func` to any thread-safe APIs after having called this API has undefined results, as `func` may have been destroyed.","examples":[{"language":"c","displayName":null,"code":"NAPI_EXTERN napi_status\nnapi_release_threadsafe_function(napi_threadsafe_function func,\n                                 napi_threadsafe_function_release_mode mode);"}],"children":[]},{"kind":"section","id":"napi_ref_threadsafe_function","name":"napi_ref_threadsafe_function","title":"`napi_ref_threadsafe_function`","scope":"module","overloadOf":null,"stability":null,"added":["v10.6.0"],"deprecated":[],"removed":[],"napiVersion":[4],"changes":[],"description":"```c\nNAPI_EXTERN napi_status\nnapi_ref_threadsafe_function(node_api_basic_env env, napi_threadsafe_function func);\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] func`: The thread-safe function to reference.\n\nThis API is used to indicate that the event loop running on the main thread\nshould not exit until `func` has been destroyed. Similar to [`uv_ref`](https://docs.libuv.org/en/v1.x/handle.html#c.uv_ref) it is\nalso idempotent.\n\nNeither does `napi_unref_threadsafe_function` mark the thread-safe functions as\nable to be destroyed nor does `napi_ref_threadsafe_function` prevent it from\nbeing destroyed. `napi_acquire_threadsafe_function` and\n`napi_release_threadsafe_function` are available for that purpose.\n\nThis API may only be called from the main thread.","summary":"This API is used to indicate that the event loop running on the main thread should not exit until `func` has been destroyed. Similar to `uv_ref` it is also idempotent.","examples":[{"language":"c","displayName":null,"code":"NAPI_EXTERN napi_status\nnapi_ref_threadsafe_function(node_api_basic_env env, napi_threadsafe_function func);"}],"children":[]},{"kind":"section","id":"napi_unref_threadsafe_function","name":"napi_unref_threadsafe_function","title":"`napi_unref_threadsafe_function`","scope":"module","overloadOf":null,"stability":null,"added":["v10.6.0"],"deprecated":[],"removed":[],"napiVersion":[4],"changes":[],"description":"```c\nNAPI_EXTERN napi_status\nnapi_unref_threadsafe_function(node_api_basic_env env, napi_threadsafe_function func);\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[in] func`: The thread-safe function to unreference.\n\nThis API is used to indicate that the event loop running on the main thread\nmay exit before `func` is destroyed. Similar to [`uv_unref`](https://docs.libuv.org/en/v1.x/handle.html#c.uv_unref) it is also\nidempotent.\n\nThis API may only be called from the main thread.","summary":"This API is used to indicate that the event loop running on the main thread may exit before `func` is destroyed. Similar to `uv_unref` it is also idempotent.","examples":[{"language":"c","displayName":null,"code":"NAPI_EXTERN napi_status\nnapi_unref_threadsafe_function(node_api_basic_env env, napi_threadsafe_function func);"}],"children":[]}]},{"kind":"section","id":"miscellaneous-utilities","name":"Miscellaneous utilities","title":"Miscellaneous utilities","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"","summary":"","examples":[],"children":[{"kind":"section","id":"node_api_get_module_file_name","name":"node_api_get_module_file_name","title":"`node_api_get_module_file_name`","scope":"module","overloadOf":null,"stability":null,"added":["v15.9.0","v14.18.0","v12.22.0"],"deprecated":[],"removed":[],"napiVersion":[9],"changes":[],"description":"```c\nNAPI_EXTERN napi_status\nnode_api_get_module_file_name(node_api_basic_env env, const char** result);\n\n```\n\n* `[in] env`: The environment that the API is invoked under.\n* `[out] result`: A URL containing the absolute path of the\n  location from which the add-on was loaded. For a file on the local\n  file system it will start with `file://`. The string is null-terminated and\n  owned by `env` and must thus not be modified or freed.\n\n`result` may be an empty string if the add-on loading process fails to establish\nthe add-on's file name during loading.","summary":"`result` may be an empty string if the add-on loading process fails to establish the add-on's file name during loading.","examples":[{"language":"c","displayName":null,"code":"NAPI_EXTERN napi_status\nnode_api_get_module_file_name(node_api_basic_env env, const char** result);\n"}],"children":[]}]}]}