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.
if you install gulp
in your node project, you can do like this:
forever start node_modules/gulp/bin/gulp.js [YOUR GULP TASK]
Try this:
forever start -c "gulp" serve
The -c
option allows you to use any command.
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
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.
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()