Search code examples
node.jsgulpnodemon

Gulp Nodemon - how do I make Nodemon exit on file change


Currently I have a very simple Gulp build script:

const gulp = require('gulp');
const ts = require('gulp-typescript');
const tsProject = ts.createProject('tsconfig.json');
const del = require('del');
const nodemon = require('gulp-nodemon');

gulp.task('build-clean', function() {
    return del('dist');
});

gulp.task('build', ['build-clean'], function () {
    return gulp.src('src/**/*.ts')
        .pipe(tsProject())
        .pipe(gulp.dest('dist'));
});

gulp.task('start', ['build'], function () {
  nodemon({
    script: 'dist/app.js'
  , ext: 'js html'
  })
})

This reloads the page on changes to JS or HTML files.

This is useful for developing, but on production I want the exact opposite. If my files change, that's because of a git push to my server. That means Jenkins will run, after that's finished Jenkins will push the code to my webfolder.

I want to stop this nodemon server if Jenkins pushes the code, because a completely fresh gulp-build will be executed, including the Nodemon server.

So - how can I make nodemon exit after files change instead of restarting?


Solution

  • Maybe should you just use nodein production instead of nodemon

    gulp.task('start', ['build'], function () {
      node({
        script: 'dist/app.js'
      , ext: 'js html'
      })
    })