hot-require-module

1.0.0 • Public • Published

node-hot-require

features

  1. hot require one,reload all module required by it
  2. ignore all module in node_modules and system module
  3. custom filter function witch file will be reload or not
// app.js
const express = require("express");
const hot = require("@ali/node-hot-require");
// filter witch file will be reload
hot.filter = function(filename) {
    if (filename.endsWith("ignore.js")) {
        return false;
    }
    return true;
};
const app = express();
 
const router = hot.require("./router.js");
 
app.use(router);
 
app.get("/upgrade", function(req, res) {
    hot.reloadAll();
    res.send("ok!");
});
 
app.listen(3000, function() {
    console.log('Listening on http://localhost:3000');
});
// router.js
var express = require('express');
var router = express.Router();
 
router.get('/', function(req, res) {
    res.send('change me!');
});
 
module.exports = router;

open http://localhost:3000

you will get change me!

edit router.js change res.send('hello world')

open http://localhost:3000/upgrade to reload router.js

open http://localhost:3000/

you will get hello world

Readme

Keywords

Package Sidebar

Install

npm i hot-require-module

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

8.16 kB

Total Files

8

Last publish

Collaborators

  • liu.xuewei