I would like to know how to reload a Node.js module at runtime.
Let's say I have the following code:
index.js
var myModule = require("./app.js");
app.js
var express = require("express");
express.listen(3000, function() {
console.log("app listening on port 3000");
});
I tried multiple ways to reload my module required in the index.js module. But the Express app won't restart.
I would like to keep the index.js running, because it handles recompiling Babel modules on the fly. And the app.js module with the express server needs to be completely restarted.
Is there any way to do this without starting a second process for the app.js?