express-refresh

Express middleware for refreshing routes during development. Does not rely on restarting the process like other implementations.

Usage no npm install needed!

<script type="module">
  import expressRefresh from 'https://cdn.skypack.dev/express-refresh';
</script>

README

Express middleware for refreshing/reloading routes during development. Does not rely on restarting the process like other implementations.

Usage:

Just require the file, and add the middleware before the express router middleware, example:

var express-refresh = require('express-refresh');
app.configure(function(){
    ...
    app.use(express-refresh());
    app.use(app.router);
    ...
});

It'll automatically detect whether or not you're in development mode, will not 'load' otherwise.

Limitations:

  1. Functions in the main express file (usually 'app.js') won't get refreshed.

Therefore any route middleware / functions will not be refreshed, example:

// this function doesn't get refreshed
var getUser = function(req,res,next){ 
    next(); };
//  but the actual routing still does
app.get('/', getUser, routes.index);
  • Only workarounds are requiring people to export their functions or...
  • making the parser be able to properly parse that and call eval() on it...
  • Or... don't write route middleware inside app.js, but put it in another file.
  1. That means this also won't be refreshed... inline functions, example:

    app.get('/', function(req,res,next){ next(); }, routes.index);

And again, the actual routing does get refreshed, just not the function.