V
V
vasIvas2015-08-18 14:07:55
Node.js
vasIvas, 2015-08-18 14:07:55

How to tell nodemon when to start?

I use gulp to run nodemon, but I already think that I will have to refuse. The reason for this is that js files are compiled on the server and nodemon is triggered every time something changes.
And I would like to postpone his call until the end of the changes. Is it possible to do so? I looked at the docks on pure nodemon and did not find it. There is something like console commands, but how can I do this from js or nodejs?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Prozorov, 2015-08-18
@vasIvas

Faced with the same problem as yours, I abandoned nodemon in favor of this task:

'use strict';

var node;
var gulp = require('gulp');
var spawn = require('child_process').spawn;

var JS_SERVER_BIN_FILE = './bin/server.js';
var JS_SERVER_SOURCE = './js/server/**/*.js';


gulp.task('supervise', function() {
    gulp.watch(JS_SERVER_SOURCE, function() {
        if (node) node.kill();

        node = spawn('node', [JS_SERVER_BIN_FILE], {stdio: 'inherit'});
        node.on('close', function (code) {
            if (code === 8) {
                console.log('Error detected, waiting for changes...');
            }
        });
    });
});


process.on('exit', function() {
    if (node) node.kill()
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question