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) // so.cpp #include <napi.h> class C1: public Napi::ObjectWrap<C1> { public: C1(const Napi::CallbackInfo &info); static void Initialize(Napi::Env& env, Napi::Object& … Read more

Importing/requiring an NAPI addon from a Webpack ReactJS/ReactTS project

I have a custom API (closed source for now), built in pure C. This API is the client side of a communication protocol (think network-based database queries). I have successfully used node-gyp to compile the C code wrappers so that the NAPI addon addon.node can function in JavaScript by calling the C. I have also written a .d.ts file, so that this addon can work from TypeScript. I have no issue with both of these use cases; ie, doing a tsc index.ts && nodejs index.js will compile and run the imported/required addon without a hitch, and the client-side operations of my C API happen without a hitch. I have made this addon into a private npm package, and have been using it in small TypeScript projects by installing it as a node_modules dependency without any issue.