Created
February 27, 2018 06:38
-
-
Save nemtsov/c182a419741ed6a0bb325fea27dcf389 to your computer and use it in GitHub Desktop.
Start two node servers in one
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* eslint no-console: 0 */ | |
const { fork, spawn } = require('child_process'); | |
const web = fork(`${__dirname}/web.js`); | |
web.on('close', code => process.exit(code)); | |
if (process.env.NODE_ENV === 'development') { | |
const api = spawn('nodemon', ['--watch', 'server', '--ext', 'js,gql,json', 'server/api.js']); | |
api.stdout.on('data', data => process.stdout.write(data)); | |
api.stderr.on('data', data => process.stderr.write(data)); | |
} else { | |
const api = fork(`${__dirname}/api.js`); | |
api.on('close', code => process.exit(code)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment