A development HTTP server with automatic live reload functionality for front-end web development
npx @tessl/cli install tessl/npm-live-server@1.2.0Live Server is a development HTTP server with automatic live reload functionality for front-end web development. It serves static files from a directory and automatically refreshes the browser when files change, eliminating the need for manual page refreshes during development.
npm install -g live-server (recommended global installation)For programmatic use in Node.js:
const liveServer = require("live-server");For ES modules:
import liveServer from "live-server";# Serve current directory
live-server
# Serve specific directory
live-server /path/to/your/project
# Serve with custom port
live-server --port=3000
# Serve with HTTPS
live-server --https=path/to/https-config.jsconst liveServer = require("live-server");
// Start server with default options
liveServer.start();
// Start with custom configuration
liveServer.start({
port: 8181,
host: "0.0.0.0",
root: "/public",
open: false,
file: "index.html",
wait: 1000
});
// Stop the server
liveServer.shutdown();Live Server consists of several key components:
http/https modules with Connect middleware stackThe live reload mechanism works by:
Complete command-line tool for quick development server setup with extensive configuration options including port, host, HTTPS, authentication, proxying, and SPA support.
live-server [PATH] [OPTIONS]
# Core options
--port=NUMBER # Port to use (default: 8080)
--host=ADDRESS # Host address (default: 0.0.0.0)
--open=PATH # Browser path to open (default: server root)
--no-browser # Suppress browser launch
# File handling
--watch=PATH # Paths to watch (comma-separated)
--ignore=PATH # Paths to ignore (comma-separated)
--entry-file=PATH # Entry file for SPA routing
# Advanced features
--https=PATH # HTTPS configuration
--cors # Enable CORS
--htpasswd=PATH # HTTP Basic authentication
--proxy=ROUTE:URL # Proxy configuration
--middleware=PATH # Custom middleware
--spa # Single Page App modeProgrammatic interface for integrating live server functionality into build tools, development environments, and custom applications.
// Main API methods
liveServer.start(options?: LiveServerOptions): http.Server | https.Server;
liveServer.shutdown(): void;
// Configuration interface
interface LiveServerOptions {
host?: string; // Address to bind (default: '0.0.0.0')
port?: number; // Port number (default: 8080, 0 = random)
root?: string; // Root directory (default: process.cwd())
open?: string | string[] | boolean; // Browser launch config
file?: string; // Entry point file for SPA
wait?: number; // Reload delay in ms (default: 100)
logLevel?: number; // 0=errors, 1=some, 2=lots (default: 2)
// File watching
watch?: string[]; // Paths to watch exclusively
ignore?: string[]; // Paths to ignore
ignorePattern?: RegExp; // Ignore pattern (deprecated)
// Features
cors?: boolean; // Enable CORS
noCssInject?: boolean; // Disable CSS injection
spa?: boolean; // Enable SPA mode
// Authentication & Security
htpasswd?: string; // Path to htpasswd file
https?: string | object; // HTTPS configuration
httpsModule?: string; // Custom HTTPS module
// Middleware & Proxying
middleware?: (string | Function)[]; // Connect middleware
mount?: [string, string][]; // Mount point mappings
proxy?: [string, string][]; // Proxy configurations
// Legacy options
browser?: string; // Browser to launch
noBrowser?: boolean; // Deprecated: use open: false
}// Server instance (return type of liveServer.start())
interface LiveServerInstance extends http.Server {
// Standard Node.js HTTP server with additional live server functionality
}
// Main LiveServer object structure
interface LiveServer {
server: http.Server | https.Server | null;
watcher: object | null; // Chokidar watcher instance
logLevel: number;
start(options?: LiveServerOptions): http.Server | https.Server;
shutdown(): void;
}