简体   繁体   中英

How to use pm2 to run grunt serve

my colleague passed me a project that you run grunt serve to start. Now I'm trying to use pm2 to start the project in the background forever so I can close my command line. However, I couldn't find a right way to do it.

I've seen answers like

cd /path/to/fullstack

pm2 start grunt --name website -- serve

but I don't quite understand and I have very little knowledge regarding grunt. All I know is that grunt serve runs multiple tasks at the same time for me.

I know that if I know the base js file that creates a web server for my app such as index.js. I can just run pm2 start index.js.

I tried to run the base file with node index.js, but it gives me an error cuz I need to run babel at the same time which is done by the grunt serve.

Can anyone help me to run grunt serve command using pm2?

I advise you to create a ecosystem file and put these configs :

script: 'grunt' and scriptArgs: ['serve']

For anyone wondering how to achieve this in 2019, here's the solution. Leverage PM2 and PM2's Ecosystem File .

First, create a file named ecosystem.config.js .

Then, do something like this:

module.exports = {
  apps : [{
    name   : 'myapp', // the name of your app
    cwd    : '/path/to/myapp', // the directory from which your app will be launched
    script : '/usr/local/bin/grunt', // the location of grunt on your system
    args   : 'serve' // the grunt command
  }]
};

Then, just run:

pm2 start ecosystem.config.js

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM