Five Server

0.4.5 · active · verified Sun Apr 19

Five Server is a modern development server with live reload capabilities, designed as a maintained fork of the popular `live-server` package. It is completely rewritten in TypeScript and aims to provide up-to-date dependencies and enhanced features compared to its predecessor. Currently at version 0.4.5, it offers features like remote logs for debugging on mobile devices, built-in PHP server support, and compatibility with Server Side Rendered applications (e.g., Express.js). While it ships with a CLI, it also offers a programmatic API for integration into projects. Key differentiators include its robust module import options for various JavaScript environments and features specifically for its VSCode extension, and it targets Node.js version 16 or higher.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to programmatically start Five Server, serving a specific directory on a custom port with live reload, without automatically opening a browser. Includes setup for a test 'public' folder.

import FiveServer from 'five-server';
import path from 'path';
import fs from 'fs';

// Create a dummy 'public' directory and an index.html file for demonstration
const publicDir = path.join(process.cwd(), 'public');
if (!fs.existsSync(publicDir)) {
  fs.mkdirSync(publicDir, { recursive: true });
}
fs.writeFileSync(path.join(publicDir, 'index.html'), '<h1>Hello Five Server!</h1><p>Watch me reload.</p>', 'utf8');

// Example: Serve the 'public' directory on port 8080 without opening a browser automatically.
const server = new FiveServer();
server.start({
  port: 8080,
  root: publicDir, // Set the document root to the 'public' directory
  open: false, // Do not open browser automatically
  watch: true, // Enable live reload
  dir: publicDir // Ensure 'dir' is also set for correct root behavior
}).then(() => {
  console.log('Five Server started on http://localhost:8080');
  console.log(`Watching for changes in: ${publicDir}`);
  console.log('Open your browser to http://localhost:8080');
}).catch(err => {
  console.error('Failed to start Five Server:', err);
});

view raw JSON →