CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-livereload

LiveReload server for monitoring files and automatically reloading web browsers

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

cli.mddocs/

Command Line Interface

Complete CLI with option parsing for all server configuration options plus path specification and help text.

Capabilities

Main CLI Entry Point

Runs the LiveReload CLI application with argument parsing and server startup.

/**
 * Main CLI entry point that parses arguments and starts server
 * Uses process.argv for argument parsing
 */
function run(): void;

Usage Examples:

# Basic usage - watch current directory
livereload

# Watch specific directory
livereload ./public

# Watch multiple directories
livereload "public, assets, templates"

# With options
livereload ./src -p 8080 -d

# Complex configuration
livereload ./public -e 'html,css,js' -x 'tmp,cache' -w 1000 -d

CLI Argument Parser

Parses command line arguments and creates server configuration for testing purposes.

/**
 * Parse CLI arguments and create server (primarily for testing)
 * @param testArgv - Array of command line arguments
 * @returns Object with server instance and parsed path
 */
function createServerFromArgs(testArgv: string[]): {
  server: Server;
  path: string | string[];
};

Usage Examples:

const { createServerFromArgs } = require('livereload/lib/command');

// For testing CLI argument parsing
const result = createServerFromArgs([
  './public', 
  '-p', '8080', 
  '-d'
]);

console.log(result.server.config.port);  // 8080
console.log(result.path);                // ['./public']

CLI Options

Basic Options

Essential CLI options for server configuration.

# Version information
livereload -v
livereload --version

# Port configuration  
livereload -p 8080
livereload --port 8080

# Host binding
livereload -b 0.0.0.0
livereload --bind 0.0.0.0

# Debug mode
livereload -d
livereload --debug

File Watching Options

Configure which files are monitored and how.

# Custom extensions (replaces defaults)
livereload -e 'html,css,js'
livereload --exts 'html,css,js'

# Additional extensions (appends to defaults)
livereload -ee 'scss,ts,jsx'
livereload --extraExts 'scss,ts,jsx'

# Specific files to reload
livereload -f 'index.html,config.js'
livereload --filesToReload 'index.html,config.js'

# Additional exclusion patterns
livereload -x 'tmp,cache,logs'
livereload --exclusions 'tmp,cache,logs'

# Use polling for file system changes
livereload -u
livereload --usepolling

# Add delay before browser notification
livereload -w 1000
livereload --wait 1000

Advanced Options

CORS, CORP, and development URL configuration.

# Enable Cross-Origin Resource Policy
livereload -cp
livereload --corp

# Enable CORS for all origins
livereload -cs
livereload --cors

# Enable CORS for specific origin
livereload -cs 'https://example.com'
livereload --cors 'https://example.com'

# Set original development URL for proxying
livereload -op 'http://localhost:3000'
livereload --originalpath 'http://localhost:3000'

Path Specification

Single Path

Monitor a single directory or file.

# Current directory (default)
livereload

# Specific directory
livereload ./public
livereload /path/to/project/dist

# Relative paths
livereload ../shared/assets

Multiple Paths

Monitor multiple directories simultaneously.

# Comma-separated paths
livereload "public, assets, templates"
livereload "./src, ./dist, ./config"

# Can be combined with options
livereload "src, dist" -p 8080 -d

Path Resolution

All paths are resolved to absolute paths internally using path.resolve().

CLI Option Details

Complete Option Reference

/**
 * CLI Options Configuration
 */
interface CLIOptions {
  // Path argument (optional)
  path?: string;                    // Directory to watch (default: '.')
  
  // Basic options
  version?: boolean;                // -v, --version: Show version
  port?: number;                    // -p, --port: Server port (default: 35729)
  bind?: string;                    // -b, --bind: Host binding (default: 'localhost')
  debug?: boolean;                  // -d, --debug: Enable debug output
  
  // File watching options  
  exts?: string;                    // -e, --exts: Extensions (comma-separated)
  extraExts?: string;               // -ee, --extraExts: Additional extensions
  filesToReload?: string;           // -f, --filesToReload: Specific filenames
  exclusions?: string;              // -x, --exclusions: Exclusion patterns
  usepolling?: boolean;             // -u, --usepolling: Use polling mode
  wait?: number;                    // -w, --wait: Delay in milliseconds
  
  // Advanced options
  corp?: boolean;                   // -cp, --corp: Enable CORP headers
  cors?: string | boolean;          // -cs, --cors: Enable CORS
  originalpath?: string;            // -op, --originalpath: Development URL
}

Usage Examples

Development Server

# Basic development setup
livereload ./public -d

# With custom port and CORS
livereload ./dist -p 8080 -cs -d

# Watch source files with build delay
livereload ./src -w 2000 -ee 'ts,scss' -d

Production-like Setup

# Bind to all interfaces with CORP headers
livereload ./public -b 0.0.0.0 -cp

# With specific CORS origin
livereload ./dist -cs 'https://myapp.com' -p 35729

Network/Docker Setup

# Use polling for network file systems
livereload /shared/project -u -d

# Docker container setup
livereload . -b 0.0.0.0 -u -w 1000 -d

Complex Configuration

# Full-featured development environment
livereload ./public \
  --port 8080 \
  --bind 0.0.0.0 \
  --debug \
  --extraExts 'ts,tsx,scss,vue' \
  --exclusions 'node_modules,tmp,cache' \
  --filesToReload 'webpack.config.js,package.json' \
  --usepolling \
  --wait 500 \
  --cors 'http://localhost:3000' \
  --originalpath 'https://api.myapp.com'

Error Handling

Common CLI Errors

The CLI handles these error conditions:

// Port already in use
if (err.code === "EADDRINUSE") {
  console.log("The port LiveReload wants to use is used by something else.");
  process.exit(1);
}

// Other server errors
process.on('uncaughtException', (err) => {
  console.error('Server error:', err);
  process.exit(1);
});

Option Validation

Invalid options are handled by the opts library:

  • Invalid port numbers are converted to NaN, then default to 35729
  • Invalid regex patterns in exclusions may cause startup errors
  • Comma-separated values are split and trimmed automatically

Integration with Package Scripts

npm scripts

{
  "scripts": {
    "dev": "livereload ./public -d",
    "dev:watch": "livereload ./src -ee 'ts,scss' -w 1000",
    "dev:network": "livereload . -b 0.0.0.0 -u -d"
  }
}

Environment Variables

While not directly supported, you can use environment variables in npm scripts:

{
  "scripts": {
    "dev": "livereload ./public -p ${PORT:-35729} -d"
  }
}

Exit Codes

  • 0: Normal termination
  • 1: Error condition (port in use, invalid arguments, etc.)

Output Format

With debug mode enabled (-d or --debug), the CLI outputs:

Starting LiveReload v0.10.3 for /path/to/directory on localhost:35729.
LiveReload is waiting for a browser to connect...
Protocol version: 7
Exclusions: /\.git\//,/\.svn\//,/\.hg\//
Extensions: html,css,js,png,gif,jpg,php,php5,py,rb,erb,coffee
Polling: false

docs

cli.md

file-watching.md

index.md

server-operations.md

tile.json