kentor / www.kentor.dev

Writing on Web Development
https://www.kentor.dev
6 stars 0 forks source link

Node.js hot module reloading development #1

Open FranckFreiburger opened 7 years ago

FranckFreiburger commented 7 years ago

Hello, Maybe you might be interested in my module-invalidate module. It allows you to invalidate a module and make it automatically reloaded on further access, thanks to ES6 Proxy.

const fs = require('fs');

var myModule = require('./myModule.js');

fs.watch(require.resolve('./myModule.js'), function() {

    module.invalidateByPath('./myModule.js');
});

setInterval(function() {

    console.log(myModule.count());
}, 1000);
Globik commented 7 years ago

Hi @FranckFreiburger , But why you are watching only one file, not a directory? Is it posible let's say to watch a directory with for example 50 files and then only one file after changes to invalidate?