7

I am using angular-fullstack for my application. I want to start my apps using pm2.

Angular-fullstack starts prodcution mode by grunt serve:dist, it runs several tasks including setting environment variables.
PM2 seems to start an application with a js file. like pm2 start server.js

My question is:
How do I use PM2 to start my application in production mode with Grunt?

I know my main application file is server/app.js, but I cannot simply do pm2 start server/app.js, because those environment variables are not properly set.

Wint
  • 2,268
  • 2
  • 22
  • 32
  • Please have a look at my answer **[here](http://stackoverflow.com/questions/25007130/how-to-use-grunt-gulp-with-pm2?rq=1)** – soyuka Nov 06 '14 at 17:43
  • 1
    Hi soyuka, I noticed your answer there. but: 1. I didn't commit node_modules. 2. I cannot find the entry script for grunt. this script does not seem to work: `node ./node_modules/grunt/lib/grunt.js serve` . Thanks your help! – Wint Nov 07 '14 at 02:02

2 Answers2

10

An alternative is to launch grunt directly using pm2:

cd /path/to/fullstack
pm2 start grunt --name website -- serve
morloch
  • 1,781
  • 1
  • 16
  • 23
6

I finally got pm2 work with grunt. just use /usr/bin/grunt as starting script and pm2 works well, the argument is passed by the args section.
Here is my ecosystem.json config file. (I am using pm2 deploy)

{
  "apps" : [{
    "name"      : "myapp",
    "script"    : "/usr/bin/grunt",
    "args"        : "['serve:dist']"
  }],
  "deploy" : {
    "production" : {
      "user" : "user-name",
      "host" : "server-address",
      "ref"  : "origin/develop",
      "repo" : "git-url",
      "path" : "/opt/deploy",
      "post-deploy" : "npm install && bower install && pm2 startOrRestart ecosystem.json --env production"
    }
  }
}
Wint
  • 2,268
  • 2
  • 22
  • 32
  • I happen to have similar problem as yours.. I'm using ```grunt server``` to start my application.. and I want pm2 to monitor the ```grunt server``` that I made.. could you help me on how to achieve it ? or do I need to use the same answer that you give ? – Eka Rudianto Oct 07 '15 at 07:05