In general, you can always use the second method template, but exportseither moduleprovide different parameters.
Using the following example:
void Init(Local<Object> exports) {
NODE_SET_METHOD(exports, "test", MyTest);
}
Add a function testas a "function property" of the export object.
Thus, you can use the following JS code and, for example, print it to stdout using the function testfrom the export object:
const test = require('./path/to/node/addon/addon.node');
test.test('my message');
On the other hand:
void Init(Local<Object> exports, Local<Object> module) {
NODE_SET_METHOD(module, "exports", MyDummyCallback);
}
(module) . - JS:
const test = require('./path/to/node/addon/addon.node');
test('test');
test tty, .