How to deploy with PM2 and Grunt

I am using angular-fullstack for my application. I want to run my applications using pm2.

Angular -fullstack starts the grunt serve:dist release mode, it launches several tasks, including setting environment variables.
PM2 seems to be launching an application with a js file. like pm2 start server.js

My question is:
How to use PM2 to run my application in production mode using Grunt?

I know that my main application file is server/app.js , but I cannot just do pm2 start server/app.js because these environment variables are set incorrectly.

+7
gruntjs pm2
source share
2 answers

I finally got a pm2 grunt job. just use /usr/bin/grunt as the start of the script, and pm2 works well, the argument is passed by the args section.
Here is my config.json config file. (I am using pm2 deployment)

 { "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" } } } 
+6
source share

An alternative is to run grunt directly using pm2:

 cd /path/to/fullstack pm2 start grunt --name website -- serve 
+10
source share

All Articles