Mini LiveReload Server
mini-lr is a JavaScript package that provides a lightweight LiveReload server implementation. It was originally forked from the `tiny-lr` project to address perceived inactivity and provide support for `npm v3` during a period when `tiny-lr` was not being actively maintained. The package exposes an HTTP server and can be used as Express/Connect middleware, offering a basic REST API to notify the server of file changes, which are then broadcast to connected LiveReload clients. It does not include file watching capabilities itself, requiring external build processes or application logic to trigger change notifications. The current stable version is 0.1.9, though the project is explicitly deprecated, with its author recommending users switch back to the now-active `tiny-lr` package. Therefore, there is no active release cadence planned for `mini-lr`.
Common errors
-
Error: Cannot find module 'mini-lr'
cause The package is not installed or the `require` path is incorrect.fixRun `npm install mini-lr` or `yarn add mini-lr` to install the package. Ensure your `require('mini-lr')` statement is correct. -
TypeError: app.use is not a function
cause `mini-lr.middleware` expects an Express/Connect `app` instance with `use` method when used with the `{ app: app }` option.fixEnsure you are passing a valid Express or Connect application instance to the `middleware` function, as shown in the integration examples: `minilr.middleware({ app: app })`. -
Error: body-parser deprecated undefined extended: provide extended option node_modules/mini-lr/index.js:77:21
cause `mini-lr`'s middleware integration relies on `body-parser`. Old versions of `body-parser` or incorrect usage might trigger deprecation warnings.fixEnsure `body-parser` is correctly configured before `mini-lr.middleware`. For Express, use `app.use(body.urlencoded({ extended: true }))` and `app.use(body.json())` with the `extended` option explicitly set to `true` or `false` (recommended `true` for general use, or `false` for simple key-value pairs).
Warnings
- deprecated The `mini-lr` package is officially deprecated by its author. Users are strongly advised to migrate back to the `tiny-lr` package, which is now actively maintained and has added contributors. Continued use of `mini-lr` is not recommended for new projects or ongoing development.
- breaking When `mini-lr` was originally forked, it was to provide `npm v3` support and address `tiny-lr`'s inactivity. While `mini-lr` itself aimed for compatibility, switching between `tiny-lr` versions or forks might have required manual updates to dependencies or `require` paths, especially if projects were locked into older `tiny-lr` versions.
- gotcha A debug module vulnerability was patched in version `0.1.9`. While this was a patch version to address a security concern in an internal dependency, it underscores the importance of staying updated or migrating to the recommended, actively maintained `tiny-lr`.
- gotcha The LiveReload browser extension typically expects the server to run on port `35729`. Using a different port will prevent the browser extension from connecting automatically. If you choose a custom port, you must manually include the LiveReload script tag in your HTML and specify the custom port.
Install
-
npm install mini-lr -
yarn add mini-lr -
pnpm add mini-lr
Imports
- minilr
import minilr from 'mini-lr';
const minilr = require('mini-lr'); - Server
const Server = require('mini-lr').Server;const { Server } = require('mini-lr'); - middleware
import { middleware } from 'mini-lr';const minilr = require('mini-lr'); const lrMiddleware = minilr.middleware;
Quickstart
const path = require('path');
const express = require('express');
const minilr = require('mini-lr');
const body = require('body-parser');
const port = process.env.LR_PORT || process.env.PORT || 35729;
const app = express();
app
.use(body.urlencoded({ extended: true }))
.use(body.json())
.use(minilr.middleware({ app: app }))
.use(express.static(path.resolve('./')))
.listen(port, function() {
console.log(`LiveReload server listening on port ${port}`);
console.log('To trigger a reload, run: curl http://localhost:35729/changed?files=index.html');
});