Created
July 25, 2018 08:30
-
-
Save paulmelero/a6862362cd49a9d2ed710dc72997c87a to your computer and use it in GitHub Desktop.
PM2 start nuxt
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
# now run in your console: (I'm actually using powershell) | |
pm2 start .\ecosystem.config.js |
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
// here we have the ecosystem file | |
// we may have different apps and environments. | |
// we can write here our environment variables or import them with "dotenv". Example: | |
// require('dotenv').config() // this will load your .env file ;) | |
// check the docks: | |
// https://pm2.io/doc/en/runtime/guide/ecosystem-file/ | |
module.exports = { | |
apps: [ | |
{ | |
name: 'at', | |
script: './start.js', | |
env: { | |
HOST: 'localhost', | |
PORT: 1234 | |
} | |
} | |
], | |
} |
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
// First, we need a js script to link in the ecosystem file, | |
// This is the script that will run our `npm start` command. | |
const exec = require('child_process').exec // Or es6 modules, you know, I'm not your supervisor. | |
console.log( | |
`Starting app for production` // you may have different envs... | |
) | |
// Here's the good part | |
// by default the command line tool will be cmd! Check the docs: | |
// https://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback | |
const build = exec('npm.cmd start', { stdio: 'inherit', windowsHide: true }) | |
build.stdout && build.stdout.on('data', console.log) | |
build.stderr && build.stderr.on('data', console.log) | |
build.on('close', (code) => { | |
if (code !== 0) { | |
console.log(`Build process exited with code ${code}`) | |
} | |
if (build.stdin) { | |
build.stdin.end() | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment