2
votes

Is there a way to run grunt serve using PM2? This way I could set up my environment to automatically start when my computer start up.

I found something like:

cd /path/to/project/
pm2 start grunt --name website -- serve

But that doesn't seem to work. I am getting the following error when looking at pm2 logs:

PM2: 2015-10-19 18:23:44: Script C:\Users\...\AppData\Roaming\npm\grunt had too many unstable restarts (15). Stopped. "errored"

grunt-0 (err):     at Module._compile (module.js:413:25)
grunt-0 (err):     at Object.Module._extensions..js (module.js:452:10)
grunt-0 (err):     at Module.load (module.js:355:32)
grunt-0 (err):     at Function.Module._load (module.js:310:12)
grunt-0 (err):     at Function._load (C:\Users\cltessie\AppData\Roaming\npm\node_modules\pm2\node_modules\pmx\lib\transaction.js:62:21)
grunt-0 (err):     at Object.<anonymous> (C:\Users\cltessie\AppData\Roaming\npm\node_modules\pm2\lib\ProcessContainerFork.js:28:21)
grunt-0 (err):     at Module._compile (module.js:434:26)
grunt-0 (err):     at Object.Module._extensions..js (module.js:452:10)
grunt-0 (err):     at Module.load (module.js:355:32)
grunt-0 (err): SyntaxError: Unexpected token case
grunt-0 (err):     at exports.runInThisContext (vm.js:53:16)
grunt-0 (err):     at Module._compile (module.js:413:25)
grunt-0 (err):     at Object.Module._extensions..js (module.js:452:10)
grunt-0 (err):     at Module.load (module.js:355:32)
grunt-0 (err):     at Function.Module._load (module.js:310:12)
grunt-0 (err):     at Function._load (C:\Users\cltessie\AppData\Roaming\npm\node_modules\pm2\node_modules\pmx\lib\transaction.js:62:21)
grunt-0 (err):     at Object.<anonymous> (C:\Users\cltessie\AppData\Roaming\npm\node_modules\pm2\lib\ProcessContainerFork.js:28:21)
grunt-0 (err):     at Module._compile (module.js:434:26)
grunt-0 (err):     at Object.Module._extensions..js (module.js:452:10)
grunt-0 (err):     at Module.load (module.js:355:32)
2
did you find any solution to run pm2 with gruntZaid Iqbal

2 Answers

1
votes

Running pm2 start grunt alone worked for me, still cannot explain why though

1
votes

Hey this worked for me.

cd /path/to/project/
pm2 start node_module/grunt/bin/grunt --name website -- serve

Explanation: PM2 will try to execute the file after start and will look it in the local path. grunt, I asume, references to the global installation of grunt. But node_module/grunt/bin/grunt is in the scope of PM2, so you can run this file.

I only use it for local development and I don't recommend this solution for production, but it can be helpful to run your app locally and check for logs in pm2. Also, if you run your back end services in the same instance of pm2, and you test something against this stack while executing "pm2 logs" you can see the whole trace of execution through all the services in order. Something very difficult even if you have some centralized logging solution like Kibana or splunk, because network lag is always messing with the order of log entries.