Nuxt.js: PM2 start

Created on 31 Aug 2017  路  9Comments  路  Source: nuxt/nuxt.js

I want to start the project with PM2锛宭ike pm2 start app.js
So锛學hich is the JS entry file?

This question is available on Nuxt.js community (#c1372)
help-wanted

Most helpful comment

Just another way of doing it ;-)

  1. install pm2 in global

npm i -g pm2

  1. start command

pm2 start npm --name "your-app-alias" -- start

  1. restart command (after re-build)

pm2 restart your-app-alias

All 9 comments

  1. install pm2 ( or use npm )
yarn add pm2
  1. modify package.json file scripts.start to use pm2 start
...
"scripts": {
    "dev": "nuxt",
    "build": "nuxt build",
    "start": "pm2 start ./node_modules/nuxt/bin/nuxt-start -i max --attach",
    "generate": "nuxt generate",
    "serverbuild": "nuxt build",
    "lint": "eslint --ext .js,.vue --ignore-path .eslintignore .",
    "precommit": "npm run lint"
  },
...

Just another way of doing it ;-)

  1. install pm2 in global

npm i -g pm2

  1. start command

pm2 start npm --name "your-app-alias" -- start

  1. restart command (after re-build)

pm2 restart your-app-alias

@NicoPennec where would we mix a yarn generate in this? before the restart?

@acidjazz yes, you can run the generate cmd before the restart.

But yarn generate is for static server!
PM2 is for dynamic server (nodejs).

You can use PM2 has static server, but it's not the main purpose.

@NicoPennec well static server or not you need to nuxt generate, and if you have dynamic routes you cant you need to still serve /dist/with nuxt for the router right?

Or maybe I'm confusing generate with build?

@NicoPennec When you run through pm2 using npm
~javscript
pm2 start npm --name "your-app-alias" -- start
~

could specify options ? (typically PORT)

I finally could make it work on Windows (with ecosystem file, npm scripts and environment variables), check out the gist:

https://gist.github.com/gangsthub/a6862362cd49a9d2ed710dc72997c87a

Hi @gangsthub ,

Thanks for update. I've personally added in my package.json

"scripts": {
  "prod": "pm2 start npm ecosystem.config.js --name nuxt -- start"
}

so I can run npm run prod
and ecosystem.config.js is

module.exports = {
  apps : [
      {
        name: "nuxt",
        script: "./node_modules/nuxt/bin/nuxt-start",
        env: {
            "HOST": "0.0.0.0",
            "PORT": 80,
            "NODE_ENV": "production",
        }
      }
  ]
}

What is basically quite the same as you do.

:heart:

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gary149 picture gary149  路  3Comments

mattdharmon picture mattdharmon  路  3Comments

surmon-china picture surmon-china  路  3Comments

VincentLoy picture VincentLoy  路  3Comments

o-alexandrov picture o-alexandrov  路  3Comments