Tiny LiveReload Fork

0.0.5 · active · verified Tue Apr 21

tiny-lr-fork is an actively maintained fork of the original `tiny-lr` package, which had become unmaintained. It provides a lightweight, background-friendly LiveReload server implementation for development workflows. Unlike the original, this fork addresses lingering issues, incorporates community contributions, and includes security patches. Key differentiators include quieter operation (reduced `console.log` output), proper handling of WSS for `livereload.js` over HTTPS, and normalized Windows file paths. The server exposes a simple HTTP/WebSocket API that build tools (like Grunt, or custom scripts) can use to notify connected LiveReload clients (browser extensions or injected scripts) about file changes. It does not perform file watching itself, requiring external integration for detecting changes. The current stable version, as per the changelog, is 2.0.0, with a release cadence driven by bug fixes and necessary updates rather than a fixed schedule.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to set up `tiny-lr-fork` as a standalone LiveReload server integrated with an Express application, listening on the default port 35729. It shows both starting the server and integrating its middleware for handling reload requests, along with an example of a custom route. It also includes `curl` commands to trigger reloads.

const tinylr = require('tiny-lr');
const path = require('path');
const express = require('express');

const PORT = 35729; // Standard LiveReload port for browser extensions
const app = express();

// Initialize tiny-lr server
const lrserver = tinylr();

// Listen for specific requests on the tiny-lr server (optional)
lrserver.on('GET /custom-status', (req, res) => {
  res.writeHead(200, { 'Content-Type': 'text/plain' });
  res.end('tiny-lr server is running and custom route works!');
});

// Integrate tiny-lr middleware with Express
// In modern Express, query parsing is built-in, but body-parser might still be needed.
app.use(express.json()); // For POST requests with JSON body
app.use(express.urlencoded({ extended: true })); // For URL-encoded bodies
app.use(lrserver.middleware({ app: app })); // Bind tiny-lr routes to the Express app

// Serve static files (e.g., your project's root)
app.use(express.static(path.resolve('./')));

// Start the Express app and tiny-lr server
app.listen(PORT, function() {
  console.log(`Express app and tiny-lr server listening on port ${PORT}`);
  console.log('Use `curl http://localhost:35729/changed?files=index.html` to trigger reloads.');
  console.log('Or `curl -X POST http://localhost:35729/changed -d "{\"files\":[\"style.css\"]}"`');
});

// Example of how to trigger a reload programmatically
// setTimeout(() => {
//   lrserver.changed({ body: { files: ['index.html'] } });
//   console.log('Triggered a reload after 5 seconds.');
// }, 5000);

view raw JSON →