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.

2
  • Please have a look at my answer here
    – soyuka
    Commented Nov 6, 2014 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
    Commented Nov 7, 2014 at 2:02

2 Answers 2

10

An alternative is to launch grunt directly using pm2:

cd /path/to/fullstack
pm2 start grunt --name website -- serve
0
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"
    }
  }
}
1
  • 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 ? Commented Oct 7, 2015 at 7:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.