In general, you can always use the second method template, but exports
either module
provide different parameters.
Using the following example:
void Init(Local<Object> exports) {
NODE_SET_METHOD(exports, "test", MyTest);
}
Add a function test
as 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 test
from 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, .