Skip to content
标签
note
字数
145 字
阅读时间
1 分钟

如果用的是 npm 发布包,go 写的那部分编译成二进制(做成平台包发布,在 postinstall 脚本里自动安装,例如 64 位 windows 上装 esbuild 的 npm 包时会自动装上 esbuild-windows-64),然后 js 里用 child_process 调用 go 编译出的二进制。

js
const exec = require('child_process').exec;
const child = exec('cat *.js bad_file | wc -l',
    (error, stdout, stderr) => {
        console.log(`stdout: ${stdout}`);
        console.log(`stderr: ${stderr}`);
        if (error !== null) {
            console.log(`exec error: ${error}`);
        }
});

不是 go 调用 js,而是 js 调用 go。
更多参考: node-gyp 实现 nodejs 调用 C++ - 掘金

参考

贡献者

The avatar of contributor named as jiechen jiechen

页面历史

撰写