node-addon-api
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
Node-addon-api is a beneficial package that serves as an abstraction layer above the Node.js C++ API (Node-API). It simplifies the creation of Native Addons for Node.js by providing a higher level, more JavaScript like API for working with Node's JavaScript data types and object properties. It means, with the help of node-addon-api, developers are able to perform direct operations on JavaScript objects from C++ code much efficiently.
To utilize the node-addon-api, you must first install it via npm, which stands for Node.js package manager. You can perform the installation using the terminal/command-line interface with the command npm install node-addon-api
. After that, you need to include the module in your project's binding.gyp
file:
'include_dirs' : ["<!(node -p \"require('node-addon-api').include\")"]
Then, in your C++ code, include the napi.h
header file at the top:
#include <napi.h>
The inclusion of this header will provide you access to the Node-addons-API. Now you can start using the API to manipulate JavaScript objects from C++ code. For instance:
Napi::Object HelloWorld(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
return Napi::String::New(env, "Hello, World!");
}
This example function returns a new JavaScript string when called from JavaScript.
For the comprehensive documentation on node-addon-api, you can visit the official GitHub page at git://github.com/nodejs/node-addon-api.git. The napi.h file also includes comments which make for detailed documentation of the API's functionalities.