简体   繁体   English

运行 child_process 以运行 server.js 文件

[英]run child_process to run server.js file

I'm getting a bit lost in child_process docs.我在child_process文档中有点迷失了。 What is the recommended way to run a server.js in a child_process ?child_process中运行server.js的推荐方法是什么?

Should I run this below?我应该在下面运行吗? Also, if I kill the main file, will it kill the child process too?另外,如果我杀死主文件,它也会杀死子进程吗?

const { exec } = require('child_process')

exec('node server.js')

Backstory : I'm trying to run webpack, but spin up the proxy api server from the webpack JS file.背景故事:我正在尝试运行 webpack,但从 webpack JS 文件启动代理 api 服务器。

So after some finicking around here is what I got to run the webpack server and express server at the same time from the same file (NOTE: they do both get killed simultanously:) )因此,在这里经过一番修饰之后,我必须从同一个文件同时运行 webpack 服务器和 express 服务器(注意:它们确实同时被杀死:))

In webpackDevServer.js在 webpackDevServer.js 中

child_process.exec('node servers/devServer.js ' + API_SERVER_PORT, (err, stdout, stderr) => {  
  if (err) {  
    throw new Error('Proxy server failed to run.', err);  
  }  
})
console.info('> API SERVER: running on port', API_SERVER_PORT)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM