Questions tagged [node.js-addon]

Native C++ addons for node.js

This tag is for node.js native addons: https://nodejs.org/api/addons.html

291 questions
6
votes
3 answers

How can you call an emitter callback from separate c++ thread in an addon?

For context, I started with this question. I need to call the callback for the emitter in another thread. I made a minimal example but it segfaults on emit.Call({cb, result}); My first instinct is that I have a problem with the lifetimes of env or…
Philip Nelson
  • 1,027
  • 12
  • 28
6
votes
0 answers

How to pass c++ object pointer back when making a node add-on

I'm making a Node add-on to expose some functions from libmpg123 to Javascript. Specifically I need to somehow pass back a pointer to a out123_handle object to javascript, which is produced from out123_new. The examples do not mention passing back a…
Khoi
  • 4,502
  • 6
  • 29
  • 31
6
votes
2 answers

How to convert v8::String to const char *

i have this function in dll static COMMANDERDLL_API int InsertCodeBar(const char* pszBuffer); in my node addon i have this function void InsertCodeBarWrapper(const FunctionCallbackInfo& args){ Isolate* isolate = args.GetIsolate(); …
Matheus Echenique
  • 137
  • 1
  • 2
  • 7
6
votes
1 answer

Passing an array from node.js to c++ v8 using NAN

I am using NAN for including a c++ library in node.js. I understand how to pass numbers and strings back and forth between the two, but I don't understand how to pass arrays. What I would like to do is something like this: index.js var test =…
nevos
  • 907
  • 1
  • 10
  • 22
6
votes
1 answer

*v8::String::Utf8Value(args[0]->ToString()) does not return the string of node.js addon argument

I've found that *v8::String::Utf8Value(args[0]->ToString()) returns the proper string on node 0.8.2 32-bit and does not return the proper string on node 0.8.8 64-bit. does anybody understand why? My node.js addon looks like this: #define…
sigflup
  • 305
  • 2
  • 11
5
votes
1 answer

v8 do not support v8::Value::ToNumber anymore?

I'm currently looking for C++ add-ons with node-gyp. node-gyp configure works fine, but node-gyp build gives an error with error C2661: 'v8::Value::ToNumber': no overloaded function take 0 parameter. There are some warnings about deprecated, and…
lee
  • 185
  • 2
  • 8
5
votes
3 answers

Understanding Node Addon API (N-API) HandleScope

I have difficulties to understand how to correctly use HandleScope and EscapableHandleScope. For example, from this Node example: MyObject::MyObject(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { Napi::Env env = info.Env(); …
jroy
  • 483
  • 6
  • 16
5
votes
4 answers

Node-Addon-Api Pass Array As Function Argument

I am trying to create a basic native node addon where a javascript array is passed from node and then processed in c++. The problem is I cannot figure out how to correctly pass the array. I can instantiate the array without issue but assigning it…
Root0x
  • 472
  • 1
  • 9
  • 28
5
votes
3 answers

node-gyp ignores (c++17) cflag

I try to configure & build a node.js C++ addon with this binding.gyp file: { "targets": [ { "target_name": "addon", "sources": [ "addon.cpp" ], "cflags": [ "-std=c++17" ] } ] } But when I run…
user1511417
  • 1,880
  • 3
  • 20
  • 41
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
1 answer

node.js Nan: call JavaScript callback in C++ function

I’m building a node-module wrapper for a C++ library to pass logging information through Nan to JavaScript. For this a NAN_Method is available to register a callback. The callback handler has to register itself as a callback at the C++ library via…
S.B.
  • 51
  • 1
  • 4
5
votes
1 answer

Error: Cannot open shared object file: No such file or directory

I was writing C++ Addon for Node.js. Tried to use sample library called libSample.so which has declaration of function printHello: void printHello() { std::cout << "Hello World\n"; } It worked fine.(Compiled using node-gyp configure build and…
Jasurbek Nabijonov
  • 1,607
  • 3
  • 24
  • 37
5
votes
1 answer

Using std::thread in Node.js Addon

Imagine that I use a synchronous function, from my Node.js addon: var check_ok = addon.my_function(parameters); var final_results = addon.final_function(parameters); But in the method code I have: std::thread t[10]; //Global //... void…
zippo
  • 95
  • 1
  • 4
5
votes
1 answer

This vs. Holder for ObjectWrap::Unwrap

The v8::FunctionCallbackInfo class distinguishes between This and Holder. I know what this is in JavaScript, and assume that This reflects that setting. But I have only a vague notion of what Holder is, and very little idea as to when I should use…
MvG
  • 57,380
  • 22
  • 148
  • 276
5
votes
1 answer

Use nan to receive and return Float32Array in an addon

I'm trying to use nan in order to calculate something on an array of floats in an add-on and then return it as a Float32Array. But while the args have IsNumber() and NumberValue()functions it only has a IsFloat32Array() function and no…
Darius
  • 707
  • 6
  • 21
1
2
3
19 20