worker process run code of master process

When I change the test.js, the console.log("Source code change, start to restart worker one by one") run 3 times?. I have one master process, so it should be one time

var cluster = require('cluster');
var fs      = require('fs');

if (cluster.isMaster) {

    for (var i = 0; i < 2; i++) {
        cluster.fork();
    }

    fs.watch('./config/test.js', function(curr, prev) {
        console.log("Source code change, start to restart worker one by one");
        delete require.cache[require.resolve('./config/config.js')];
    })

}else{
    var config = require('./config/test.js')
}

Somehow your watchdog (fs.watch) is triggered three times, maybe because you write three blocks of data? Maybe it would trigger more often when the file becomes bigger? (Maybe WinSCP it truncating the file before writing?)

I assume you want to trigger only when the file is uploaded completely?

Unfortunately you can't catch the message IN_CLOSE_WRITE from inotify(..).

So do something like var old = to; to = setTimeout(function() { clearTimeout(old); /* insert real stuff here */ }, 1000) inside your fs.watch. The function then would fire only once, if the file keeps changing within the 1000 ms...