node-addon-api is the C++ wrapper for N-API, the ABI stable library to build addons for Node.js.
Questions tagged [node-addon-api]
126 questions
                    
                    20
                    
            votes
                
                4 answers
            
        Node.js native addons: where is node_api.h located?
I'm trying to create a native addon for Node.js and when I include
#include 
The Intelli Sense of VS Code says that it cannot detect where node_api.h is located (it's included by napi.h). 
node-gyp build works well and it compiles. But I do… 
         
    
    
        RussCoder
        
- 889
- 1
- 7
- 18
                    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
                    7
                    
            votes
                
                1 answer
            
        How to avoid node-gyp rebuild when running yarn install?
When I run yarn install, my native add on is always rebuilt. It can be seen that the command node-gyp rebuild is run instead of node-gyp build, even if nothing is updated.
caros@ubuntu:~/Developer/xviz-converter$ yarn install
yarn install…
         
    
    
        Jing Li
        
- 639
- 7
- 18
                    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
                    6
                    
            votes
                
                1 answer
            
        Catch c++ native addon cout/console messages in electron.js or node.js app
C++ native module's std::cout console message don't get printed on console once module gets build.   
Is there any way to print runtime std::cout messages on console AND then we can catch those messages in electron app using node.js    
How does…
         
    
    
        AtiqGauri
        
- 1,483
- 13
- 26
                    5
                    
            votes
                
                1 answer
            
        Getting raw pointer from shared_ptr to pass it to function that requires raw
Ok first off I'm very new to C++ so apologies if my understanding is poor. I'll try explain myself as best I can. What I have is I am using a library function that returns a std::shared_ptr, I then have a different library function that… 
         
    
    
        Nick Hyland
        
- 357
- 1
- 10
                    5
                    
            votes
                
                1 answer
            
        Is it possible to debug a node c++ addon within electron application with a common debugger (gdb, lldb, etc.)?
I am trying to debug a node add-on that is called within an electron application but I can not find a way to launch or attach an c debugger to the app. I have had success in debugging it when it's called by a simple node application, by calling node…
         
    
    
        Paulo Alvim
        
- 63
- 1
- 5
                    4
                    
            votes
                
                1 answer
            
        Calling a C(++) function from Node.JS using N-API
I want to use a C-Function from Node.js by using N-API with node-addon-api module wrapper. This is the first time with N-API for me and I'm also a beginner with Node and C++. I have a experience in C programming of embedded systems but this Node.jS…
         
    
    
        groboter
        
- 81
- 2
- 6
                    4
                    
            votes
                
                1 answer
            
        Local native Node module causes error: Uncaught Error: No native build was found for platform=win32 arch=x64 runtime=electron abi=75 uv=1 libc=glibc
I have a native Node addon I wrote that I'm trying to add to an Electron app. I use npm install /path/to/addon to install the addon. Then electron-rebuild and electron-build, which don't complain.
But when I run npm start, in the dev console I get…
         
    
    
        Frederik Petersen
        
- 1,025
- 3
- 16
- 30
                    4
                    
            votes
                
                1 answer
            
        How do I return a BigInt type from C++ to javascript using N-API?
I'm using this https://github.com/nodejs/node-addon-api/blob/master/doc/bigint.md document as a reference to return a bigint from c++ but I'm getting the following error:
error: ‘BigInt’ in namespace ‘Napi’ does not name a type
     Napi::BigInt…
         
    
    
        Ameet Gohil
        
- 93
- 1
- 6
                    3
                    
            votes
                
                1 answer
            
        Returning c++ object instance with node-addon-api
In javascript the code i trying to run is
const Element = require("element.node");
let element = new Element();
console.log(element.parent); // null
element.parent = element;
console.log(element.parent === element); // should be true
So in the cpp…
         
    
    
        NeoPlasme
        
- 31
- 2
                    3
                    
            votes
                
                1 answer
            
        In a Node.js C++ addon, SetWindowsHookEx's callback is never called
This is a simple Windows C++ keylogger example
When I ran it in Visual Studio, HookCallback is called correctly.
I want to do the same thing using node-addon-api in Node.js but I don't want to log key presses in a file, I want to send the keycode…
         
    
    
        aabuhijleh
        
- 2,214
- 9
- 25
                    2
                    
            votes
                
                1 answer
            
        Node-addon-api - construct ObjectWrap from C++
I'm new to NAPI, and I'm trying to convert and old Nan code to NAPI.
What happens is that I have a structure like this:
class PointWrapper : public Napi::ObjectWrap {
public:
  static void init(Napi::Env env, Napi::Object exports);
 … 
         
    
    
        Maurício Szabo
        
- 677
- 1
- 6
- 13
                    2
                    
            votes
                
                0 answers
            
        How to handle signals gracefully in the Electron.js application?
I'm trying to implement signal handling in the Electron.js application to call a custom function either in C++ code or JS code (ex. segmentation fault). In one of the node addons, I did it using std::signal method and it works for macOS but on…
         
    
    
        asmbaty
        
- 436
- 2
- 11
                    2
                    
            votes
                
                1 answer
            
        Constructing native object from NodeJS Addon
Expectation
I want to to implement using a native NodeJS module that works like the javascript module below
class C1{
  make(){return new C2()}
}
class C2{}
module.exports({C1, C2})
Approach
My attempt was, (among some other failed attempts)
//…
         
    
    
        Bob
        
- 13,867
- 1
- 5
- 27