Domanda

Can we compile Node.js modules separately and load them runtime as we can do with modules in Flex? My requirement is to avoid restarting Node.js every time we change the code of modules.

È stato utile?

Soluzione

I don't think you can do hot swapping while running a node.js application.

Node.js keeps the required module in cache during the lifetime of the application. However, you can do something like

delete require.cache[require.resolve('./module.js')]

Or if you want to reload all the modules, then

for (var key in require.cache) {
    delete require.cache[key];
}

This will delete the cached key from require cache and force node.js to reload the module next time when require('./module.js') occurs.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top