使用C语言开发去素数的nodejs插件,c语言代码如下
1  | 
  | 
安装node-gyp
npm install -g node-gyp
创建node-gyp的软连接
ln -s /usr/local/node/bin/node-gyp /usr/bin
创建binding.gyp
1  | {  | 
编译编写的c语言
node-gyp configure
执行后生成build文件夹
node-gyp build
目录结构如下
1  | build  | 
编译完成,编写测试的index.js
1  | const addon = require('./build/Release/addon');  | 
执行结果如下:
1  | { '0': 2,  |