Sign inDemoInstall


Package Overview
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies



Node.js API (Node-API)

Version published
Weekly downloads
decreased by-0.68%
Install size
378 kB
Weekly downloads

Package description

What is node-addon-api?

The node-addon-api package is a helper library for building Node.js Addons in C++. It provides a C++ API that abstracts away the complexities of working with the low-level V8 and N-API provided by Node.js, making it easier to develop native addons.

What are node-addon-api's main functionalities?

Object Wrapping

Object wrapping allows C++ classes to be represented as JavaScript objects. It provides an easy way to create and manage objects that have a one-to-one relationship with C++ objects.

Napi::ObjectReference MyClass::constructor;

MyClass::MyClass(const Napi::CallbackInfo& info) : Napi::ObjectWrap<MyClass>(info) {
  // constructor implementation

Napi::Object MyClass::Init(Napi::Env env, Napi::Object exports) {
  Napi::HandleScope scope(env);

  Napi::Function func = DefineClass(env, "MyClass", {
    InstanceMethod("myMethod", &MyClass::MyMethod)

  constructor = Napi::Persistent(func);

  exports.Set("MyClass", func);
  return exports;

Function Arguments

The package provides a way to handle function arguments passed from JavaScript to C++ with type checking and conversion utilities.

Napi::Value MyFunction(const Napi::CallbackInfo& info) {
  Napi::Env env = info.Env();
  if (info.Length() < 2) {
    Napi::TypeError::New(env, "Expected at least two arguments").ThrowAsJavaScriptException();

  Napi::String arg0 = info[0].As<Napi::String>();
  double arg1 = info[1].As<Napi::Number>().DoubleValue();

  // function implementation

  return Napi::String::New(env, "result");

Asynchronous Operations

node-addon-api provides utilities for performing asynchronous operations, allowing long-running tasks to be executed without blocking the Node.js event loop.

class MyAsyncWorker : public Napi::AsyncWorker {
  MyAsyncWorker(Napi::Function& callback) : AsyncWorker(callback) {}

  void Execute() override {
    // Do work in another thread

  void OnOK() override {
    Napi::HandleScope scope(Env());
    Callback().Call({Env().Null(), Napi::String::New(Env(), "Success")});

Napi::Value RunAsyncWork(const Napi::CallbackInfo& info) {
  Napi::Function callback = info[0].As<Napi::Function>();
  MyAsyncWorker* worker = new MyAsyncWorker(callback);
  return info.Env().Undefined();

Other packages similar to node-addon-api



2024-03-01 Version 8.0.0, @legendecas

Notable changes

  • Support for Node.js v16.x is no longer maintained.


  • [df2147a2b6] - build(deps): bump github/codeql-action from 3.24.3 to 3.24.5 (dependabot[bot]) #1455
  • [eb4fa9b55a] - build(deps): bump actions/dependency-review-action from 4.1.0 to 4.1.3 (dependabot[bot]) #1452
  • [f85e8146bb] - build(deps): bump github/codeql-action from 3.23.2 to 3.24.3 (dependabot[bot]) #1448
  • [b84deb0d2f] - build(deps): bump actions/dependency-review-action from 4.0.0 to 4.1.0 (dependabot[bot]) #1447
  • [7dcee380cd] - build(deps): bump actions/setup-node from 4.0.1 to 4.0.2 (dependabot[bot]) #1444
  • [a727b629fe] - build(deps): bump actions/upload-artifact from 4.3.0 to 4.3.1 (dependabot[bot]) #1443
  • [ea712094e3] - build(deps): bump step-security/harden-runner from 2.6.1 to 2.7.0 (dependabot[bot]) #1440
  • [898e5006a5] - build(deps): bump github/codeql-action from 3.23.1 to 3.23.2 (dependabot[bot]) #1439
  • [66e6e0e4b6] - build(deps): bump actions/upload-artifact from 4.0.0 to 4.3.0 (dependabot[bot]) #1438
  • [f1ca4ccd7f] - build(deps): bump actions/dependency-review-action from 3.1.5 to 4.0.0 (dependabot[bot]) #1433
  • [c58112d52e] - build(deps): bump github/codeql-action from 3.23.0 to 3.23.1 (dependabot[bot]) #1430
  • [f1b9c0bc24] - chore: remove v16.x regular CI runs (Chengzhong Wu) #1437
  • [c6561d90d6] - chore: reduce dependabot noise (Chengzhong Wu) #1436
  • [42931eeba6] - doc: reorganize readme (Chengzhong Wu) #1441
  • [3b9f3db14e] - doc: update changelog maker commands (Chengzhong Wu) #1431
  • [034c039298] - test: heed npm_config_debug (Gabriel Schulhof) #1445



node-addon-api module


This module contains header-only C++ wrapper classes which simplify the use of the C based Node-API provided by Node.js when using C++. It provides a C++ object model and exception handling semantics with low overhead.

API References

API references are available in the doc directory.

Current version: 8.0.0

(See for complete Changelog)

node-addon-api is based on Node-API and supports using different Node-API versions. This allows addons built with it to run with Node.js versions which support the targeted Node-API version. However the node-addon-api support model is to support only the active LTS Node.js versions. This means that every year there will be a new major which drops support for the Node.js LTS version which has gone out of service.

The oldest Node.js version supported by the current version of node-addon-api is Node.js 18.x.


The use of badges is recommended to indicate the minimum version of Node-API required for the module. This helps to determine which Node.js major versions are supported. Addon maintainers can consult the Node-API support matrix to determine which Node.js versions provide a given Node-API version. The following badges are available:

Node-API v1 Badge Node-API v2 Badge Node-API v3 Badge Node-API v4 Badge Node-API v5 Badge Node-API v6 Badge Node-API v7 Badge Node-API v8 Badge Node-API v9 Badge Node-API Experimental Version Badge


We love contributions from the community to node-addon-api! See for more details on our philosophy around extending this module.

Team members


NameGitHub Link
Anna Henningsenaddaleax
Chengzhong Wulegendecas
Jack XiaJckXia
Kevin EadyKevinEady
Michael Dawsonmhdawson
Nicola Del GobboNickNaso
Vladimir Morozovvmoroz


NameGitHub Link
Arunesh Chandraaruneshchandra
Benjamin Byholmkkoopa
Gabriel Schulhofgabrielschulhof
Hitesh Kanwathirthadigitalinfinity
Jason Ginchereaujasongin
Jim Schlightjschlight
Sampson Gaosampsongao
Taylor Wollboingoing


Licensed under MIT



Last updated on 05 Mar 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.


Related posts

SocketSocket SOC 2 Logo


  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc