{"id":16216,"library":"simple-hot-reload-server","title":"Simple Hot Reload Server","description":"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.","status":"maintenance","version":"1.2.0","language":"javascript","source_language":"en","source_url":"https://github.com/moyuyc/simple-hot-reload-server","tags":["javascript","hot","reload","server"],"install":[{"cmd":"npm install simple-hot-reload-server","lang":"bash","label":"npm"},{"cmd":"yarn add simple-hot-reload-server","lang":"bash","label":"yarn"},{"cmd":"pnpm add simple-hot-reload-server","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The package primarily uses CommonJS `module.exports`, so `require()` is the idiomatic way. While Node.js might handle ESM `import` for named exports, `require()` ensures compatibility given the package's architecture.","wrong":"import { start } from 'simple-hot-reload-server';","symbol":"start","correct":"const { start } = require('simple-hot-reload-server');"},{"note":"Accesses the `HotReloadServer` class for programmatic instantiation. Follows the CommonJS `require()` pattern, as it's a named export from the main module.","wrong":"import HotReloadServer from 'simple-hot-reload-server';","symbol":"HotReloadServer","correct":"const { HotReloadServer } = require('simple-hot-reload-server');"},{"note":"The primary intended usage is as a command-line tool via `hrs` (after global installation or `npx`). Direct import of `hrs` as a default export is not supported, and its core functionality is exposed through the CLI or named exports like `start`.","wrong":"import hrs from 'simple-hot-reload-server';","symbol":"CLI Usage","correct":"npx hrs [path] --port 8082"}],"quickstart":{"code":"/* hrs.config.js */\nmodule.exports = {\n  // Default port is 8082, can be overridden by CLI -p option\n  port: 8082,\n  // Watch for changes in .html, .htm files by default\n  // hotRule: /\\.(html|htm)$/, \n  proxy: {\n    '/api': {\n      target: 'http://localhost:3000', // Example backend API\n      changeHost: true\n    }\n  },\n  setUp: function (app) {\n    // app is an Express server object\n    app.get('/hello', (req, res) => {\n      res.send('Hello from custom Express route!');\n    });\n  }\n};\n\n/* public/index.html */\n<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n  <meta charset=\"UTF-8\">\n  <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n  <title>Simple Hot Reload</title>\n  <link rel=\"stylesheet\" href=\"./style.css\">\n</head>\n<body>\n  <h1>Welcome!</h1>\n  <p>This content will hot reload.</p>\n  <button onclick=\"alert('Hello from inline JS!');\">Click Me</button>\n  <script src=\"./script.js\"></script>\n</body>\n</html>\n\n/* public/style.css */\nbody {\n  font-family: sans-serif;\n  background-color: #f0f0f0;\n  color: #333;\n}\nh1 {\n  color: #007bff;\n}\n\n/* public/script.js */\nconsole.log('Script loaded. Changes here will also hot reload.');\ndocument.addEventListener('DOMContentLoaded', () => {\n  const p = document.querySelector('p');\n  if (p) {\n    p.textContent = 'Content updated by JavaScript and will hot reload!';\n  }\n});\n\n// To run:\n// 1. Save the above files in your project directory:\n//    - hrs.config.js in the root\n//    - index.html, style.css, script.js inside a 'public' folder\n// 2. Open your terminal in the project root and run:\n//    npx simple-hot-reload-server public\n// 3. Open http://localhost:8082 in your browser.\n//    Modify index.html, style.css, or script.js and save to see hot reload.","lang":"javascript","description":"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."},"warnings":[{"fix":"For non-HTML/HTM files to trigger hot reloads, configure the `hotRule` option in your `hrs.config.js` to match the desired file extensions (e.g., `/\\.(html|htm|css|js)$/`).","message":"The package's primary mechanism for hot reloading is explicitly limited to files ending with `.html`, `.htm`, or files that are required by these HTML/HTM files. Other file types might not trigger a hot reload unless specifically configured via `hotRule` in `hrs.config.js` or if they are indirectly included by HTML.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Thoroughly test with your target Node.js version and browser environments. Consider alternative, more actively maintained live/hot-reloading development servers (e.g., `live-server`, `browser-sync`) if encountering modern compatibility challenges.","message":"The project appears to be in maintenance mode, with its last commit observed in late 2021. This could lead to compatibility issues with newer Node.js versions, updated browser standards, or modern JavaScript syntax/features if not actively kept up-to-date by the community or direct contributions.","severity":"gotcha","affected_versions":"<=1.2.0"},{"fix":"Ensure `hrs.config.js` uses CommonJS syntax (`module.exports = { ... }`). If you need to include ESM-only modules, you might need to use dynamic `import()` within the CommonJS context if your Node.js version supports it.","message":"The `hrs.config.js` file, which is crucial for advanced configurations like proxies and custom Express middleware, is designed as a CommonJS module (`module.exports`). Attempting to use ESM `import`/`export` syntax directly in this configuration file will result in errors.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Specify an alternative port using the `-p` or `--port` command-line option, for example: `npx simple-hot-reload-server -p 8083 public`.","cause":"The default port 8082 is already in use by another application or process on your system.","error":"Error: listen EADDRINUSE :::8082"},{"fix":"If not using `npx`, install it globally: `npm install -g simple-hot-reload-server`. Alternatively, ensure you are running it via `npx` from your project root: `npx simple-hot-reload-server [path]`.","cause":"The `hrs` command-line tool is not globally installed or `npx` cannot locate it.","error":"hrs: command not found"},{"fix":"Verify that your `hrs.config.js` includes a `hotRule` that matches the file extensions you expect to hot reload. For instance, `hotRule: /\\.(html|htm|css|js)$/` would enable hot reloading for CSS and JS files.","cause":"The `hotRule` configuration might not match the file types you are editing, or the files are not `html`/`htm` or directly referenced by them.","error":"Files are not hot reloading despite changes being saved."}],"ecosystem":"npm"}