Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jpbberry/express-router-reload

Reload your express routes super easily
https://github.com/jpbberry/express-router-reload

developer-tools express express-js express-router

Last synced: about 1 month ago
JSON representation

Reload your express routes super easily

Awesome Lists containing this project

README

        

# express-router-reload
Easy to use, hot swapper for your express routes.

## Examples
```js
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:

```js
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!
```

### Links
[NPM Package](https://npmjs.com/package/express-router-reload)\
[GitHub](https://github.com/jpbberry/express-router-reload)\
[Creator's Website](https://www.jt3ch.net)