express-router-reload
v1.0.2
Published
Reload your express routes super easily
Downloads
2
Maintainers
Readme
express-router-reload
Easy to use, hot swapper for your express routes.
Examples
const express = require('express'); // normal express what nots
var app = express();
var router = require('./routers/router.js');
const RR = require('express-router-reload');
let reloader = new RR(app);
app.use("/route", router);
// After whatever else. Let's say you change the file
delete require.cache[require.resolve("./routers/router.js")];
router = require('./routers/router.js');
//now
reloader.reload("/route", router);
// Overwrites the old router with the new refreshed one!
An easier way:
const RR = require('express-router-reload');
let reloader = new RR(app);
//express stuff...
reloader.reloadFromFile("/route", path.resolve(__dirname, "./routes/router.js"));
//The second paramater MUST be the full path.
//This basically just does the delete require.cache[require.resolve(path)] for you!