通过 Gulp 停止 运行 nodemon

Stop running nodemon via Gulp

我的想法是,我会使用 nodemon 启动一个具有特定端口的应用程序,然后 运行 我的测试,最后停止 运行ning 应用程序,这样我就可以随时再次 运行 它.

gulp.task('test', function(cb) {
    nodemon({
        script: 'server.js',
        env: { 
            'NODE_ENV': 'test' 
        }
    });

    // Run tests....


    // Stop the application and exit running Gulp -> How to do this?
});

有没有办法停止或强制 ctrl+c 运行ning gulp?

谢谢,

凯文

我得到了这些

require('shelljs/global'); // https://github.com/shelljs/shelljs

gulp.task('test', ['nodemon-test', 'mocha-test']);

gulp.task('nodemon-test', function(cb) {
    nodemon({
        script: 'server.js',
        env: { 
            'NODE_ENV': 'test' 
        }
    })
    .on('start', function() {
        cb();
    })
});

gulp.task('mocha-test', ['nodemon-test'], function() {
    exit(1);
});