0

I'm getting a bit lost in child_process docs. What is the recommended way to run a server.js in a child_process ?

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.

Kevin Danikowski
  • 4,620
  • 6
  • 41
  • 75

1 Answers1

0

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 :) )

In 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)
Kevin Danikowski
  • 4,620
  • 6
  • 41
  • 75