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
37
votes
6 answers

Error: Cannot find module 'nan'

I'm working on native Node.js addon and following nan docs I included nan into binding.gyp like: "include_dirs" : [ "
Rax Wunter
  • 2,677
  • 3
  • 25
  • 32
30
votes
3 answers

Could one write a native Node.js extension in Go, as opposed to C++?

That's all there is to my question, really, but I think it's an interesting thing to have answered.
user3025492
  • 2,853
  • 4
  • 18
  • 19
26
votes
1 answer

node-ffi vs. node extension for accessing existing C++ functionality

I've got some existing C++ code that does numerical processing within a stand-alone C++ application. I now want to use that code within a new node.js application. Researching how to access C++ code from node.js, two options come up: Write a node.js…
pancake
  • 3,232
  • 3
  • 22
  • 35
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
23
votes
6 answers

Is it possible to write a node.js extension in C (not C++)?

A quick google search yields at least one tutorial for writing a C++ "Hello World" for node.js, but it's unclear if it's possible to write such an extension using only C. Assuming it is possible, what challenges / limitations would I face?
noahlz
  • 10,202
  • 7
  • 56
  • 75
11
votes
2 answers

custom node.js addon can be built but not able to include

I am writing a custom node.js addon by C++ mixed with C program. The addon.cc consists of something like #define BUILDING_NODE_EXTENSION #include #include using namespace v8; using namespace node; /* other logic and…
Harold Chan
  • 799
  • 3
  • 11
  • 31
11
votes
4 answers

Typescript declarations file for Node C++ Addon

I have a Node C++ Addon that provides a wrapped class similar to the one in the Node documentation. I can require() my addon and then get the constructor for my class to create an instance. const { MyClass } = require('myaddon'); const obj = new…
Doug Schaefer
  • 515
  • 3
  • 10
10
votes
4 answers

Call C++ library from Node.js (Node addons / node-ffi)

I'm trying to integrate an external C++ library (I have access to the .so file as well as the header files) into my Node.js application. After a lot of research my options are reduced to: Writing a Node addon Use node-ffi From node-ffi's…
Miki de Arcayne
  • 538
  • 1
  • 7
  • 15
8
votes
1 answer

How to use node-addon-api's AsyncContext asynchronously

The docs for AsyncContext have this example (only slightly modified, but still working) that works synchronously: #include "napi.h" void MakeCallbackWithAsyncContext(const Napi::CallbackInfo& info) { Napi::Function callback =…
Evgeniy Berezovsky
  • 18,571
  • 13
  • 82
  • 156
8
votes
1 answer

How to use node.js built in modules from C++ addons

I need to use node.js built in module 'crypto' from my C++ addon. I tried to find examples of C++ addons which use built in modules, but failed. I looked in node_crypto.h/.cc and it has so different function signatures comparing with node.js crypto…
Dzenly
  • 1,611
  • 12
  • 18
7
votes
4 answers

How to use napi_threadsafe_function for NodeJS Native Addon

I've been looking through the NAPI documentation to try and understand how it deals with multithreading. According to the documentation napi_create_threadsafe_function() and napi_call_threadsafe_function() are used to create and call js functions…
Frederik Petersen
  • 1,025
  • 3
  • 16
  • 30
7
votes
1 answer

Streaming data into a Node.js C++ Addon with N-API

I am building a C++ addon for NodeJS and I want to stream data asynchronously from C++ to Node. I have found this article, https://nodeaddons.com/streaming-data-into-a-node-js-c-addon/, however; I want to use the N-API instead of NAN. I have been…
Philip Nelson
  • 1,027
  • 12
  • 28
7
votes
1 answer

Node.js Script doesn't exit

I am noob at Js but trying to make life easier by writing api to transfer files from irc to my server After some digging I got a module that downloads file (code below based on npm xdcc) but when I run the module it doesn't exit after completing…
Solaris
  • 674
  • 7
  • 22
7
votes
1 answer

execl crashes C++ node.js-addon

As normal C++ execl works fine (compiling with g++ ok.cc -o ok.elf) #include int main(){ execl("/usr/bin/python", "/usr/bin/python", nullptr); } But crashes, when works as node.js C++ addon #include #include…
7
votes
2 answers

VS Code debug C++ Node Addon

I try to setup debugging in visual studio code for a C++ Node-Addon compiled with GYP. I want to step through the source-code if possible. I use typescript as my server language and include the ".node" file compiled by gyp. This works fine but how…
Silvan Hau
  • 85
  • 1
  • 8
1
2 3
19 20