ericclemmons / hot-module

Reload changed files in Node *without* restarting the server (like nodemon/piping/etc.)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

hot-module

const { createServer } = require("http");

// πŸ‘‡ Polyfill `module.hot`
require("hot-module")();

if (module.hot) {
  // πŸ‘‡ Watch `./app` for changes
  module.hot.accept("./app", function() {
    console.log("πŸ”  Hot-reloaded `./app`");
  });

  console.info("βœ…  Server-side HMR Enabled!");
} else {
  console.info("❌  Server-side HMR Not Supported.");
}

createServer((req, res) => {
  // πŸ‘‡ Always reference latest `./app` between requests
  require("./app")(req, res);
}).listen(3000, () => {
  console.log("πŸš€ Listening at http://localhost:3000");
});

Related Projects

About

Reload changed files in Node *without* restarting the server (like nodemon/piping/etc.)


Languages

Language:JavaScript 100.0%