We have already covered how to write a simple C++ hello world native addon in a previous post. Now, we are going to add dependencies to that simple example, manage them with Conan and run the code in Node.js.
If you are not familiar with Conan, please check the getting started in the documentation.
As we explained in the previous post the native addons are usually built generating a project file for your build-system using node-gyp.
With Node.js addons we can load our C++ libraries as if they were ordinary Node.js modules. The recommended way to implement these addons is using the N-API. The N-API is delivered as a part of the Node.js distribution. since v8 and became stable in v10.
One “Hello World” addon could look something like this:
// hello.cpp #include <node.h> namespace demo { using v8::FunctionCallbackInfo; using v8::Isolate; using v8::Local; using v8::Object; using v8::String; using v8::Value; void HelloWorld(const FunctionCallbackInfo<Value>& args) { Isolate* isolate = args.