CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-live-server

A development HTTP server with automatic live reload functionality for front-end web development

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

index.mddocs/

Live Server

Live 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.

Package Information

  • Package Name: live-server
  • Package Type: npm
  • Language: JavaScript
  • Installation: npm install -g live-server (recommended global installation)
  • Node.js Support: >=0.10.0

Core Imports

For programmatic use in Node.js:

const liveServer = require("live-server");

For ES modules:

import liveServer from "live-server";

Basic Usage

Command Line Usage

# 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.js

Node.js API Usage

const 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();

Architecture

Live Server consists of several key components:

  • HTTP/HTTPS Server: Built on Node.js http/https modules with Connect middleware stack
  • File Watcher: Uses Chokidar for efficient file system monitoring
  • WebSocket Communication: Faye-WebSocket for real-time browser-server communication
  • Code Injection: Automatically injects WebSocket client code into HTML files
  • Static File Server: Custom static server with live reload integration
  • Middleware System: Connect-compatible middleware support for extensibility

The live reload mechanism works by:

  1. Watching for file changes using Chokidar
  2. Injecting WebSocket client code into served HTML files
  3. Sending reload/refresh messages to connected browsers via WebSocket
  4. Handling CSS updates without full page reload when possible

Capabilities

Command Line Interface

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 mode

Command Line Interface

Node.js Programmatic API

Programmatic 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
}

Node.js API

Types

// 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;
}

docs

cli.md

index.md

nodejs-api.md

tile.json