Questions tagged [n-api]

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 (for example, 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 underlying JavaScript engine and allow modules compiled for one major version to run on later major versions of Node.js without recompilation.

For more information refer to the official reference: https://nodejs.org/api/n-api.html

61 questions
2
votes
1 answer

Calling cpp function from NodeJS which has argument const int16_t *bar but getting error unbound type

I am trying to call CPP function from NodeJS typedef struct foo { uint8_t *data; int dataSize; } foo ; foo *ExtractBar(const int16_t *bar); I have tried nbind library in NodeJS. but getting unbound type error. uint16 =…
Mohit Sahu
  • 177
  • 2
  • 17
2
votes
0 answers

What is the meaning of `code` in `napi_throw_type_error` structure?

In the context of N-API node_api.h, what is the maining of the field code of the function napi_throw_type_error? The documentation only says "Optional error code to be set on the error.", usually what kind of data should this contain? My function…
2
votes
0 answers

Creating napi_value from node.js native addon worker pool thread

Is it possible to create napi_value from a node.js (native) worker thread and share the value with the main thread. For example: napi_create_async_work( env, NULL, resource_name, Execute, OnComplete, DataEx,…
Satyan
  • 1,346
  • 8
  • 15
2
votes
1 answer

How can we access memory outside of a Node.js application?

For example, suppose there is some other program outside of Node.js, that wants to coordinate with a Node.js application to give it direct access to some memory. On the JavaScript side, I suppose we'll need an ArrayBuffer. Do we need to write a…
trusktr
  • 44,284
  • 53
  • 191
  • 263
2
votes
1 answer

Calling JS function multiple times from different node addon methods

I'm trying to initialize my node addon module using JS callback for logging. Initialize method is intended to store callback value for calling from other methods. So I add reference to the callback using napi_create_reference. But when I'm trying to…
2
votes
2 answers

Forward arraybuffer from C to JS with node-api

Im currently trying to do some low level coding with JS. For that reason im using https://nodejs.org/api/n-api.html to add custom C code to my node.js runtime. I get passing values and changing them in c to work, even reading arraybuffers and…
1
vote
0 answers

Node addon "Check failed: IsEmpty()"

I have a Node addon related to a failure, when I destroy an object. I have no idea which object is causing that. Here is some features I am using. I have a project where I create a few objects using Napi::ObjectWrap, some asynchronous functions that…
Bob
  • 13,867
  • 1
  • 5
  • 27
1
vote
1 answer

Call `FnOnce` from `Fn`

I'm working with two different libraries (specifically napi-rs and callback-future) and want to invoke a FnOnce function from one library in a Fn function from another. Specifically, I'm trying to expose a Rust function to JavaScript which completes…
Douglas Parker
  • 1,164
  • 11
  • 20
1
vote
1 answer

Capturing stdout/stderr of Node-API module running in Electron

I'm developing a Node-API module together with an Electron application. The N-API module is running in the render process of Electron, since it has a pretty complex API, that would be hard to get through a context bridge, and I'm only planning on…
bruh_master
  • 33
  • 1
  • 3
1
vote
1 answer

Node addon don't work in electron, but worked in nodejs

I wrote a nodejs addon, compiled with node-gyp. It won't work on electron, but nodejs worked. The nodejs and electron node has the same version. The addon do these things: Load ffmpeg static library and open a rtsp or local file. Convert the frame…
Yohanan
  • 13
  • 2
1
vote
1 answer

How to call a nodejs async function from napi native code and wait until the async promise is resolved

I'm trying to call a nodejs async function from c++ that returns a promise that will be fufilled later using napi Napi::Value napiStatus = this->nodejsFunction.Call(someArgs) I want to wait until the promise is finished and get napiStatus to be…
1
vote
1 answer

What does `napi_throw_error` do when called from an asynchronous N-API addon's `napi_async_complete_callback`?

I recently completed making an asynchronous version for all the functions in a pure C API, wrapped with N-API to work with JS/TS as a nodejs addon. The last problem I had to fix was making sure that C POSIX-style errors (ie, returned integer codes)…
Tristan Duquesne
  • 512
  • 1
  • 6
  • 16
1
vote
0 answers

How to link and package external library with node-gyp for electron

I created a native OCR module using N-API (node-addon-api) with bindings to tesseract OCR. My intention is to get native OCR working under electron. I basically checked all the npm packages related to OCR and they all don't work with electron. And…
stoefln
  • 14,498
  • 18
  • 79
  • 138
1
vote
1 answer

NAPI Call Emit inside a c++ Lambda fucnction

I'm working on a N-API addon to capture video frame using windows graphic capture API , extract frame bytes and send it back to JavaScript. I have tried the event emitter but I can't get the data. Here is my C++ code: #include // my other…
Raid Lafi
  • 91
  • 1
  • 12
1
vote
1 answer

N_API How to send int value parameters to Napi::CallbackInfo

This My first node.js and n_api. I have been using PHP/APACHI. But I need the c++ library for my web And I decided to using n_api. The problem is that the value sent by ajax is always 0 in c++. I don't know what is problem. ex) I using a…
이승현
  • 81
  • 2
  • 9