N-API (pronounced N as in the letter, followed by API) is an API for building native Addons. It is independent from the underlying JavaScript runtime (ex 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 JavaScript engine and allow modules compiled for 1 version to run on later versions of Node.js without recompile.
Questions tagged [node.js-napi]
15 questions
24
votes
2 answers
Node JS addons - NAN vs N-API?
I am looking to working on a project using node js addons with C++. I came across two abstract library NAN and N-API that I can use. However I am unable to decide which one I should use. I was not able to find proper comparison between these two…

The Prenx
- 483
- 4
- 15
5
votes
1 answer
Node.js N-API addon - how to stringify/parse JSON?
I'm writing an addon for Node.js using N-API (the C interface, not to be confused with the node-addon-api C++ wrapper around N-API) which receives JSON-formatted data from an external source and needs to execute a JS callback function on its object…

Aaron Burke
- 486
- 3
- 12
5
votes
2 answers
Most basic example of adding a OpenCV C++ add-on to node.js
So lately I've been getting into OpenCV with C++.
I've built up a few libraries and apps that I would like to export over to Nodejs, but I can't figure it out for the life of me.
I tried to check out how he did it in this repo below, but it was a…

Bk Razor
- 1,492
- 1
- 14
- 24
3
votes
1 answer
NodeJS and N-API
I am trying to compile and use a N-API Node JS c++ addon. The code compiles fine but at runtime I get the following error:
module.js:664
return process.dlopen(module, path._makeLong(filename));
^
Error: Module did not…

John Gorter
- 2,162
- 2
- 17
- 25
3
votes
1 answer
Migrating old Addons to NAPI
I'm new to Node.js addons, I don't understand the difference between nan and n-api.
And is there an easy way to migrate an addon for old version (node v.0) to a newer version (node v.8)?

Idkingz
- 31
- 1
2
votes
2 answers
How to know which of the several ways to make a C/C++ nodeJS addon is used by a particular example or repo?
Apparently a situation has evolved over the years where there are three, four, or five main ways to write a nodeJS addon in C/C++ depending on where you're reading about it.
For those of us just trying to learn and write our first addon in 2021 it…

hippietrail
- 15,848
- 18
- 99
- 158
2
votes
2 answers
nodejs napi module did not self register
when i try to test nodejs N-API modules, the has a error to me:
my addon.c file is that:
#include
napi_value HelloMethod (napi_env env, napi_callback_info info) {
napi_value world;
napi_create_string_utf8(env, "world", 5,…

bingxl
- 21
- 4
2
votes
1 answer
How to call a reference function asynchronously, from N-api, I can not get "env"!
js code is:
const obj = tap.create();
quote.on("connection", (params) => {
console.log('[DEBUG js]', 'connection called, params:', params);
});
remember function in c++:
napi_create_reference(env, args[1], 1, &cbMap[eIt->second]);
when native…

张恩奇
- 21
- 2
1
vote
2 answers
Issue while calculating float value using NodeJS N-API
Hello everyone,
Coming from the web dev world. I am currently trying to do some C code which is converting an RGB value to an XYZ value that can be used by NodeJS through N-API. The issue that I have is regarding to float calculation. Below is the…

Yellowman
- 93
- 1
- 4
1
vote
1 answer
Calling a C function with Node.js N-API shows output not expected
I'm new to Node.js N-API. Let me go straight to the question.
I'm trying to call a C function Camellia_Ekeygen with N-API, but the output of the function m_uKttWork is different from calling the same function directly with C++ code.
Here're the…

wyericso
- 11
- 3
1
vote
1 answer
Emitting a Node.js Event from a C++ callback function
In a Node.js application, I need to be notified when the default audio device has been changed. This program will be used on Windows 7.
Currently I am trying to do this by making a C++ add-on for node that, through the…

Jack
- 520
- 2
- 16
0
votes
1 answer
Is it possible to make a new method on a standard nodeJS object such as "fs" using C++/napi etc?
I'm interested in making my first native C/C++ addon for nodeJS.
Conceptually it's a filesystem method that acts on a path or a file descriptor and is closely related to fs.stat() and friends.
From reading the documentation and looking at N-API…

hippietrail
- 15,848
- 18
- 99
- 158
0
votes
1 answer
N-API wrap not finding function
I have a simple N-API wrapper around a C++ class. The class is getting instantiated and deconstructed, but the instance variable in the class is not being declared, i.e. the stdout shows the exports do not contain "App.m_variable".
I've read through…

JohnA
- 699
- 2
- 7
- 15
0
votes
3 answers
firebase cloud function with N-API deployment failed
Trying to find out if it's possible to run firebase cloud functions with native code (using N-API). I have a simple "hello world" example which works fine under emulator, however when I try to deploy it I get INVALID_ARGUMENT error:
status: {
…

PrimeSeventyThree
- 940
- 2
- 9
- 24
0
votes
1 answer
Iterate Napi::Object Properties (Keys) in Node.js C++ N-API
I am having a problem using c++ n-api api and I have reviewed the documentation here, and I do not see a way to iterate the keys of a Napi::Object. I must be missing something because this is possible in JavaScript, so it must be possible in the C++…

Matthew James Briggs
- 2,085
- 2
- 28
- 58