Skip to content

Instantly share code, notes, and snippets.

@Waltari10
Created November 9, 2019 16:15
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/edf7ebb0db26b441d0ac51d66bbb8bf4 to your computer and use it in GitHub Desktop.
Save Waltari10/edf7ebb0db26b441d0ac51d66bbb8bf4 to your computer and use it in GitHub Desktop.
// execSync allows us to run system commands synchronously
const { execSync } = 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;
// Same as runnin "npm run serve" in terminal
execSync(`npm run serve -- -l ${ port} ./build`, (err, stdout, stderr) => {
if (err) {
// node couldn't execute the command
return;
}
// the *entire* stdout and stderr (buffered)
console.log(`${stdout}`);
console.log(`${stderr}`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment