Run Gulp script with forever?

后端 未结 5 786
-上瘾入骨i
-上瘾入骨i 2021-02-19 05:44

Is it possible to run Gulp script with forever?

I have Gulp script that would like to run as a daemon, so I could start / stop / list it.

相关标签:
5条回答
  • 2021-02-19 06:01

    if you install gulp in your node project, you can do like this:

    forever start node_modules/gulp/bin/gulp.js [YOUR GULP TASK]

    0 讨论(0)
  • 2021-02-19 06:01

    Try this:

    forever start -c "gulp" serve

    The -c option allows you to use any command.

    0 讨论(0)
  • 2021-02-19 06:05

    Install pm2

    $ npm install pm2 -g
    

    Now start gulp

    pm2 start gulp serve
    

    You can view running services using pm2 l and Note: sometimes you can see your services running on next to port you specified example: http://localhost:3001 instead of http://localhost:3000

    0 讨论(0)
  • 2021-02-19 06:09

    Okay, so I solved it by linking the gulp binary from /usr/bin to my local folder and then simply running the command locally. Like so:

    ln -s /usr/bin/gulp ./gulp
    forever start gulp serve
    

    The commands may vary for you but I hope you get the gist of it.

    0 讨论(0)
  • 2021-02-19 06:21

    To give you a programatic answer:

    You use the underlying forever-monitor which contains the core functionality which the forever CLI package uses.

    var forever = require('forever-monitor');
    
    gulp.task('server', function () {
        new forever.Monitor('path/to/server-script.js').start();
    });
    

    You can run multiples of such tasks, you don't need to use special daemon options since gulp tasks use orchestrator under the hood which runs tasks concurrently.

    If using CMD+C in the console is not suitable to stop your tasks then you can put it into a variable:

    var child = new forever.Monitor('path/to/server-script.js');
    child.on('event', cb) / child.start() / child.stop()
    
    0 讨论(0)
提交回复
热议问题