{"library":"node-api-headers","title":"Node-API Headers","description":"The `node-api-headers` package provides the essential C/C++ header files required for building Node.js native add-ons using the Node-API (formerly N-API). These headers enable developers to create native modules that benefit from ABI stability across different Node.js versions, simplifying maintenance and ensuring forward compatibility. The package, currently at version 1.8.0, maintains a frequent release cadence, often monthly or bi-monthly, specifically tracking and incorporating updates from the Node.js core repository. This package is crucial for build tools like `node-gyp` and `CMake.js`, which rely on these headers to compile native C/C++ code into `.node` files runnable within Node.js applications. It differentiates itself by being the official source for these headers, abstracting away the need to download full Node.js source distributions for native module development.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install node-api-headers"],"cli":null},"imports":["N/A (not a JavaScript module)","#include <node_api.h> (in C/C++)","require('node-api-headers').include_dir"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"/* file: myaddon.cc */\n#include <node_api.h>\n\nnapi_value Method(napi_env env, napi_callback_info info) {\n  napi_value greeting;\n  napi_status status;\n\n  status = napi_create_string_utf8(env, \"Hello from Node-API C++ addon!\", NAPI_AUTO_LENGTH, &greeting);\n  if (status != napi_ok) return nullptr;\n  return greeting;\n}\n\nnapi_value Init(napi_env env, napi_value exports) {\n  napi_status status;\n  napi_property_descriptor desc = {\n    \"hello\", 0, Method, 0, 0, 0, napi_default, 0\n  };\n  status = napi_define_properties(env, exports, 1, &desc);\n  if (status != napi_ok) return nullptr;\n  return exports;\n}\n\nNAPI_MODULE(NODE_GYP_MODULE_NAME, Init)\n\n/* file: binding.gyp */\n{\n  \"targets\": [\n    {\n      \"target_name\": \"myaddon\",\n      \"sources\": [ \"myaddon.cc\" ],\n      \"include_dirs\": [\n        \"<!@(node -p \\\"require('node-api-headers').include_dir\\\")\"\n      ]\n    }\n  ]\n}\n\n/* file: index.js */\nconst addon = require('bindings')('myaddon');\nconsole.log(addon.hello());\n","lang":"javascript","description":"This quickstart demonstrates how to create a basic Node.js native add-on using Node-API headers. It includes a C++ source file (`myaddon.cc`), a `binding.gyp` file for `node-gyp` to compile the add-on, and a JavaScript file (`index.js`) to load and use the compiled native module. The `binding.gyp` file dynamically fetches the header path from the `node-api-headers` package.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}