如果启动形式gulp,则使用pm2启动应用程序

时间:2022-03-16 20:18:35

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:

嗨,我正在按照教程构建一个nodejs应用程序。本教程使用gulp,运行我的应用程序我只是做gulp dev开始所有事情。在我的gulpfile中,我有:

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

./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 * and google, but cant get anything done. If someone can help me would be great. Thank you in advance.

有可能以某种方式使用pm2与这个gulp设置,我在*和谷歌中看到了一些问题,但无法完成任何事情。如果有人可以帮助我会很棒。先谢谢你。

1 个解决方案

#1


8  

It's available at http://pm2.keymetrics.io/docs/usage/pm2-api/

它可以在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

从https://github.com/Unitech/PM2/issues/1525#issuecomment-134236549实施

#1


8  

It's available at http://pm2.keymetrics.io/docs/usage/pm2-api/

它可以在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

从https://github.com/Unitech/PM2/issues/1525#issuecomment-134236549实施