Hi I was following a tutorial to build an nodejs app. This tutorial is using gulp, to run my app I just do gulp dev
to start all things. In my gulpfile I have:
var fs = require('fs')
var gulp = require('gulp')
fs.readdirSync(__dirname+'/gulp').forEach(function(task){
require('./gulp/' + task)
})
gulp.task('dev', ['watch:css', 'watch:js', 'dev:server'])
The code in ./gulp/server.js
var gulp = require('gulp')
var nodemon = require('gulp-nodemon')
gulp.task('dev:server', function(){
nodemon({
script: 'server.js',
ext:'js',
ignore: ['ng*', 'gulp*', 'assets*'],
env: { 'NODE_ENV': require('../config').ENV }
})
})
Is it possible somehow to use pm2 with this gulp setup, I saw some questions in stackoverflow and google, but cant get anything done. If someone can help me would be great. Thank you in advance.
When the server restarts, it will automatically restart PM2, which will then restart all the Node. js applications/processes it is managing. In this article, we will show you how to deploy PM2 as a service to reliably manage your Node.
Yes. Use pm2 start npm --no-automation --name {app name} -- run {script name} . It works.
It's available at http://pm2.keymetrics.io/docs/usage/pm2-api/
var gulp = require('gulp');
var pm2 = require('pm2');
gulp.task('dev:server', function () {
pm2.connect(true, function () {
pm2.start({
name: 'server',
script: 'server.js',
env: {
"NODE_ENV": require('../config').ENV
}
}, function () {
console.log('pm2 started');
pm2.streamLogs('all', 0);
});
});
});
Implementation from https://github.com/Unitech/PM2/issues/1525#issuecomment-134236549
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With