Home

NAPI

N-API, also known as Node-API, is a stable C API for building native addons for Node.js. Its goal is to provide an ABI-stable interface that allows addons to be compiled once and run across multiple Node.js versions without recompilation. By abstracting away engine-specific details, N-API aims to reduce the churn caused by changes to the underlying JavaScript engine.

The API defines a set of types and functions that enable native code to create and manipulate

N-API was developed by the Node.js community to provide binary compatibility across Node.js releases independent of

JavaScript
values,
objects,
and
functions,
invoke
JavaScript
from
native
code,
and
handle
errors.
Core
concepts
include
an
environment
handle
(env),
opaque
JavaScript
value
handles
(napi_value),
and
result
codes
(napi_status).
It
also
supports
module
registration,
property
access,
function
creation,
and
lifecycle
management,
as
well
as
asynchronous
work
and
thread-safe
calls.
The
standard
interface
is
designed
to
be
language-agnostic,
with
C
as
the
primary
implementation
language,
while
bindings
for
C++
are
commonly
provided
via
higher-level
wrappers.
the
JavaScript
engine
behind
Node
(such
as
V8).
Addons
compiled
against
a
given
N-API
version
typically
remain
usable
on
newer
Node.js
versions
as
long
as
that
N-API
version
remains
supported.
Node-Addon-API
is
a
popular
C++
wrapper
that
simplifies
working
with
N-API.
Build
tooling
such
as
node-gyp
and
cmake-js
support
compiling
against
N-API.
The
ecosystem
uses
.node
addon
binaries
loaded
via
require,
enabling
native
performance
and
functionality
within
Node.js
applications.