Simple Hot Reload Server

1.2.0 · maintenance · verified Tue Apr 21

Simple Hot Reload Server is a command-line utility and Node.js module designed for front-end development, providing a local HTTP server with automatic browser reloading capabilities. It connects clients and the server via WebSockets to enable hot reloading for HTML, CSS, and JavaScript files, among others. Key features include a file viewer, source map preview, and a request forwarding proxy. It also offers a debugger integration. This package is currently at version 1.2.0. While it provides essential development server features, its last significant activity was in late 2021, suggesting it is in maintenance mode rather than active development. Its configuration is typically handled via a CommonJS `hrs.config.js` file, allowing for custom Express middleware and advanced proxy rules.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates setting up a `simple-hot-reload-server` with a basic `hrs.config.js` for custom routes and proxying, alongside simple HTML, CSS, and JS files for hot reloading.

/* hrs.config.js */
module.exports = {
  // Default port is 8082, can be overridden by CLI -p option
  port: 8082,
  // Watch for changes in .html, .htm files by default
  // hotRule: /\.(html|htm)$/, 
  proxy: {
    '/api': {
      target: 'http://localhost:3000', // Example backend API
      changeHost: true
    }
  },
  setUp: function (app) {
    // app is an Express server object
    app.get('/hello', (req, res) => {
      res.send('Hello from custom Express route!');
    });
  }
};

/* public/index.html */
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Simple Hot Reload</title>
  <link rel="stylesheet" href="./style.css">
</head>
<body>
  <h1>Welcome!</h1>
  <p>This content will hot reload.</p>
  <button onclick="alert('Hello from inline JS!');">Click Me</button>
  <script src="./script.js"></script>
</body>
</html>

/* public/style.css */
body {
  font-family: sans-serif;
  background-color: #f0f0f0;
  color: #333;
}
h1 {
  color: #007bff;
}

/* public/script.js */
console.log('Script loaded. Changes here will also hot reload.');
document.addEventListener('DOMContentLoaded', () => {
  const p = document.querySelector('p');
  if (p) {
    p.textContent = 'Content updated by JavaScript and will hot reload!';
  }
});

// To run:
// 1. Save the above files in your project directory:
//    - hrs.config.js in the root
//    - index.html, style.css, script.js inside a 'public' folder
// 2. Open your terminal in the project root and run:
//    npx simple-hot-reload-server public
// 3. Open http://localhost:8082 in your browser.
//    Modify index.html, style.css, or script.js and save to see hot reload.

view raw JSON →