Run application with pm2 if gulp form starts

Hi, I followed the tutorial on creating a nodejs application. This tutorial uses gulp to run my application, I just do gulp dev to start it all. 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']) 

Code c. / 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 to somehow use pm2 with this gulp installation, I saw several questions in stackoverflow and google, but I can not do anything. If someone can help me, it will be great. Thank you in advance.

+6
source share
1 answer

It is 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

+8
source

All Articles