Search code examples
javascriptgulpmocha.jsnodemon

Stop running nodemon via Gulp


Here's the idea, I would start an app with specific port using nodemon then run my tests, and finally stop the running app so I could run it again anytime.

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?
});

Is there a way to stop or force ctrl+c the running gulp?


Solution

  • I got it with these

    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);
    });