使用 require() 加载插件


已编译的插件二进制文件的文件扩展名是 .node(与 .dll.so 相反)。 require() 函数用于查找具有 .node 文件扩展名的文件并将它们初始化为动态链接库。

The filename extension of the compiled addon binary is .node (as opposed to .dll or .so). The require() function is written to look for files with the .node file extension and initialize those as dynamically-linked libraries.

When calling require(), the .node extension can usually be omitted and Node.js will still find and initialize the addon. One caveat, however, is that Node.js will first attempt to locate and load modules or JavaScript files that happen to share the same base name. For instance, if there is a file addon.js in the same directory as the binary addon.node, then require('addon') will give precedence to the addon.js file and load it instead.