Can we launch a node command on a mac without node installed when using electron-packager?

拟墨画扇 提交于 2019-12-02 04:04:06

Yes, we can run a packaged app which runs a child node process even on a system with no node installed. One can use 'fork' method to run a node process and by setting the ELECTRON_RUN_AS_NODE env variable. Please find the sample code below.

 let func = () => {
   const child = childProcess.fork(path, args, 
   {
     detached: true, 
     stdio: 'ignore',
     env: {
        ELECTRON_RUN_AS_NODE: 1
     }
   }

 });

 child.on('error', (err) => {
   console.log("\n\t\tERROR: spawn failed! (" + err + ")");
 });

 child.on('exit', (code, signal) => {
   console.log(code);
   console.log(signal);
 });

 child.unref();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!