npm 0.6.0 · VS Code extension

Five Server: save a file, see the change

Five Server is a development server with live reload. Run it in a project folder and the browser reloads when you save. CSS changes swap in without a full reload.

Five Server is a TypeScript rewrite of live-server by Tapio Vierros. It is not a git fork.

$five-server

Five Server running at:

> Local: http://localhost:5500

> Local: http://127.0.0.1:5500

Tip: to open this on another device on your network (e.g. a phone),

start with --host=0.0.0.0 or set host: '0.0.0.0' in your config.

09:53:13 [Five Server] CSS change detected css/style.css

09:53:15 [Five Server] change detected index.html

$

01 How it works

Watch, notify, reload

Five Server serves your files over HTTP and opens a WebSocket on the same port. It adds a small script to each HTML page it serves. When a file changes, it sends one short message to every open page.

  1. Your editor Save

    The editor writes the file to disk.

  2. chokidar Watch

    The file watcher reports the change. Bursts of changes wait 100 ms by default and send one message.

  3. WebSocket Notify

    The server sends reload, or refreshcss for a CSS file, to each open page.

  4. Browser Update

    The page reloads. For CSS, the stylesheet links are swapped and the page keeps its state.

The script is served as /fiveserver.js and added to HTML responses for you. Plain HTML projects need no changes. The watcher covers the whole project folder unless you set watch.

02 Why use it

Built for the save-and-check loop

Each feature below is an option you turn on, or a default you can rely on.

CSS without a full reload

Stylesheets swap in place. A form you filled in, or a video you were watching, keeps its state.

Test on your phone

Set host to 0.0.0.0. Open the Network address on any device on the same Wi-Fi.

Logs from the phone

remoteLogs prints the browser console in your terminal, so you can debug a device without a cable.

Single-page apps

--spa serves index.html for routes that do not match a file.

Backends and server-rendered pages

proxy forwards requests such as /api to your backend. Server-rendered pages can load the same reload script.

Safe defaults

It binds to 127.0.0.1, hides dotfiles such as .env, and allows CORS for this computer.

03 Quick start

One command to start, one file to configure

Run five-server in your project folder. Add a config file only when the defaults are not what you need. The file is read when the server starts, so restart after you change it.

Flag What it does
--port=8080Port to listen on. Default: 5500.
--host=0.0.0.0Accept connections from other devices on your network.
--root=distFolder to serve. Default: the current folder.
--open=/about.htmlPage to open in the browser.
--no-browserDo not open a browser window.
--spaFall back to index.html for unknown routes.
--proxy=/api:http://localhost:3000Forward a path to another server.
--no-css-injectFull reload for CSS changes too.
terminal
# install once, then run in any project folder
npm i -g five-server
cd my-site
five-server

# or run it without installing
npx five-server
fiveserver.config.js
// fiveserver.config.js
module.exports = {
  port: 5500,
  host: '0.0.0.0',           // reachable from your phone
  remoteLogs: 'magenta',     // phone console logs in this terminal
  watch: ['css', 'js'],      // only these folders trigger a reload
  ignore: /\.map$/i
}

04 Origin

A rewrite of live-server, not a git fork

live-server by Tapio Vierros is the original. Five Server started from its code and was rewritten in TypeScript by Yannick Deubel. It is not a git fork. Five Server has its own repository and history, which starts from a new initial commit in March 2021. That history does not contain commits from live-server.

live-server Five Server
Author Tapio Vierros (tapio/live-server) Yannick Deubel (yandeu/five-server)
Language JavaScript TypeScript
Latest npm version 1.2.2 0.6.0
Relationship The original project A rewrite that started from live-server's code
Git history Its own repository Its own repository, not shared with live-server

The entry point still says it was forked from live-server 1.2.1, and it keeps Tapio Vierros's copyright line. Credit stays with the original.

05 VS Code

Five Server inside the editor

The Five Server extension, published by yandeu as yandeu.five-server, runs the same server from the status bar. It is on the Visual Studio Marketplace.

  • Go Live. A status bar button starts and stops the server.
  • Open from the explorer. Right-click a file or a folder and choose Open with Five Server.
  • Keyboard. Alt+L Alt+O opens the current file. Alt+L Alt+C closes the server. On macOS, use Cmd+L Cmd+O and Cmd+L Cmd+C.
  • Instant Update. The page updates while you type. Set injectBody to turn it on.
  • Highlight. The element you are editing is highlighted in the browser. It also needs injectBody.
style.css
http://localhost:5500

Hello

Saved. Updated in place.

Five Server: running on 5500

Two extensions, two authors

The Five Server extension depends only on the five-server npm package and bufferutil. It has no dependency on, and shares no code with, the Live Server extension. That extension is ritwickdey.LiveServer, published under the ritwickdey publisher ID. It is not tapio's project, and it is separate from live-server.

06 FAQ

Common questions

Found a bug or have an idea? Open an issue on the Five Server repository.

Should I remove live-server first?
Yes. Both packages install a live-server command. The README suggests running npm -g rm live-server before you install Five Server.
Is host 0.0.0.0 safe?
Only on a network you trust. Every device on that network can read the files in your project.
Why did a page reload when I changed an unrelated file?
The default watch covers the whole project folder. Set watch and ignore to narrow it.
Does it work with Express or other server-rendered apps?
Yes. Add the script tag from the docs to your server-rendered pages, then run Five Server next to your app. The repository has an Express example.

07 Install

Get Five Server

Install the npm package for the command line, or the VS Code extension for the editor. Both use the same server.

$npm i -g five-server

$five-server --help