javascript - Reload modules on the fly in Node REPL -


i testing module repl this:

repl.start({     input: process.stdin,     output: process.stdout })     .context.mymodule = mymodule; 

is there way reload module automatically, when change , save it, without having exit , run repl again?

you can use chokidar module , force reload (you lose runtime context in module, should auto-reload).

var ctx = repl.start({     input: process.stdin,     output: process.stdout })     .context;  ctx.mymodule = require('./mymodule');  chokidar.watch('.', {ignored: /[\/\\]\./}).on('all', function(event, path) {     delete require.cache['./mymodule'];     ctx.mymodule = require('./mymodule'); }); 

if doesn't work, i'm happy play little , working solution.


edit: if doesn't garbage-collect cleanly (there open handles/listeners), leak each time reloads. may need add 'clean-exit' function mymodule stop gracefully, , call inside watch handler.


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -