Run Gulp script with forever?

后端 未结 5 762
-上瘾入骨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: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()
    

提交回复
热议问题