Questions tagged [node-addon-api]

node-addon-api is the C++ wrapper for N-API, the ABI stable library to build addons for Node.js.

126 questions
2
votes
1 answer

Can Napi::Env be used in a child thread?

I wrote a sample program to pass the Napi::Env object to the child thread for use, but an error occurred during runtime. the sample code is as follows: #include #include #include #include Napi::String…
Robert
  • 31
  • 2
2
votes
1 answer

How to return float32 array from c++ in node-addon-api?

I am trying to run c++ in node.js using node-addon-api. I've read one well-written elaborate article from medium. But I want to pass to one of my functions a float, and a float array to another function. I want to return a float array from both of…
agt-ru
  • 73
  • 1
  • 7
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
0 answers

Electron Crash on calling a native addon which is using window's uiautomation library to detect button in another window

I have a native addon which detect zoom meeting window and find some button in it. That Native addon is made using NAPI(node-addon-api) and when I run it, it works fine...(give me that button name). But when I try to run that native addon in…
2
votes
1 answer

Is it possible to create an ObjectWrap in node-addon-api with a private js constructor and that can be instantiated in c++ only?

I'm currently writing a node.js addon in c++ using the node-addon-api (Napi). From what I saw in the different docs and tutorials, every objet has to extend Napi::ObjectWrap to be considered as js object. Then the constructor can be called in…
midugh
  • 608
  • 5
  • 21
2
votes
1 answer

Comparison between nodejs addons and wasm

Which is the better way to intergrate C/C++ or Rust code into Electron App for CPU intensive tasks, nodejs addons or wasm? Please compare these two methods in efficiency, compatibility and so on.
2
votes
1 answer

how to convert node v8 string to c++ string

i am new to write node c++ addon. i want to change params string from node to change c++ string, but i got error, and i try this issue, How to convert std::string to v8's Local it didn't work. i have tried these function, but none is…
2014
  • 103
  • 2
  • 9
2
votes
1 answer

How to export object from c to node addon api

I have c++ code wrapped using node-addon-api: Napi::String Method(const Napi::CallbackInfo &info) { Napi::Env env = info.Env(); time_t rawtime; struct tm *timeinfo; char system_date_buffer[80]; char iso_date_buffer[80]; time(&rawtime); …
kittu
  • 6,662
  • 21
  • 91
  • 185
2
votes
1 answer

how to implement node-nan callback using node-addon-api

Until now I've only implemented synchronous node-addon-api methods, i.e., a JavaScript function makes a call, work is done, and the addon returns. I have big gaps in knowledge when it comes to the inner workings of v8, libuv, and node, so please…
bmacnaughton
  • 4,950
  • 3
  • 27
  • 36
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
2 answers

How to avoid Segmentation fault when using N-API?

I'm trying to build a node-js wrapper for the C++ library Clip using the node addon api (N-NAPI). I want to retrive an image from a user's clipboard and pass it to JavaScript in a node.js buffer. This is what I have tried: (only the relevant…
x d
  • 473
  • 2
  • 4
  • 12
2
votes
0 answers

NodeJs Cannot find custom native module (C++ and node-addon-api)

I built my own NodeJs Module with node-addon-api in C++ and now I want to use it in an electron.js app. But unfortunetly stuck with can not find module error. My project structure is like the following: / /build /Release myAddon.node …
pospich0815
  • 378
  • 1
  • 3
  • 13
2
votes
1 answer

node-gyp Node.js addon using node-addon-api is not overriding c++ version on linux

I have successfully built a c++ addon for node.js on Mac OS. Trying to port to Linux (Centos7). I am using node.js version 12.10, node-gyp version 5.0.3, node-addon-api version 1.7.1. Centos version 7.6.1810, gcc version 7.3.1 20180303 (Red Hat…
2
votes
1 answer

NAPI native module in C++ is executing partially (Included std::thread)

My Node-js native module written with NAPI is executing partially.I have used multiple threads in it.While running module sometime it prints that thread is started but sometime it don't.And in either way module never reach the end of c++ code. I…
AtiqGauri
  • 1,483
  • 13
  • 26
2
votes
1 answer

Napi::ObjectWrap: is a destructor called and how?

I'm building an addon for node.js thanks to the node-addon-api. Each of my 'traditionals' C++ classes is wrapping a C object. Then my Napi::ObjectWrap classes wrap these C++ objects. my_object -> MyObject -> Napi::ObjectWrap The…
Benoît Lahoz
  • 1,270
  • 1
  • 18
  • 43
1
2
3
8 9