Skip to content

Instantly share code, notes, and snippets.

@Waltari10
Created November 10, 2019 06:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Waltari10/dd6edebbef41afd336d3a925f0880de1 to your computer and use it in GitHub Desktop.
Save Waltari10/dd6edebbef41afd336d3a925f0880de1 to your computer and use it in GitHub Desktop.
// exec allows us to run cmd commands in code
const { exec } = require('child_process');
// process.env.PORT is defined by Heroku environment. Use 3200 as fallback if outside of Heroku.
const port = process.env.PORT || 3200;
console.log('Port: ' + port)
const cmdStr = `.\\node_modules\\.bin\\serve -l ${ port} ./build`
console.log(cmdStr)
// Same as running ".\node_modules\.bin\serve -l 3200 ./build" in cmd
exec(cmdStr, (err) => {
if (err) {
console.error('Something went wrong!', err)
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment