cnpm i -g pkg 安装pkg
pkg . --target win --output test.exe 打包node
electron调用node程序
import {spawn} from "child_process"
// 启动服务
let cmdStr = D:/test.exe
let serverProcess = spawn(cmdStr)
serverProcess.stdout.on("data", function (data) {
console.log("启动服务器成功! stdout:" + data)
})
// 关闭后台服务
function stopServer() {
if (serverProcess) {
kill(serverProcess.pid, "SIGTERM", function () {
serverProcess = null;
})
}
}