CSS without a full reload
Stylesheets swap in place. A form you filled in, or a video you were watching, keeps its state.
npm 0.6.0 · VS Code extension
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
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.
The editor writes the file to disk.
The file watcher reports the change. Bursts of changes wait 100 ms by default and send one message.
The server sends reload, or refreshcss for a CSS file, to each open page.
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
Each feature below is an option you turn on, or a default you can rely on.
Stylesheets swap in place. A form you filled in, or a video you were watching, keeps its state.
Set host to 0.0.0.0. Open the Network address on any device on the same Wi-Fi.
remoteLogs prints the browser console in your terminal, so you can debug a device without a cable.
--spa serves index.html for routes that do not match a file.
proxy forwards requests such as /api to your backend. Server-rendered pages can load the same reload script.
It binds to 127.0.0.1, hides dotfiles such as .env, and allows CORS for this computer.
03 Quick start
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=8080 | Port to listen on. Default: 5500. |
--host=0.0.0.0 | Accept connections from other devices on your network. |
--root=dist | Folder to serve. Default: the current folder. |
--open=/about.html | Page to open in the browser. |
--no-browser | Do not open a browser window. |
--spa | Fall back to index.html for unknown routes. |
--proxy=/api:http://localhost:3000 | Forward a path to another server. |
--no-css-inject | Full reload for CSS changes too. |
# 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
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
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
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.
injectBody to turn it on.injectBody.Hello
Saved. Updated in place.
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
Found a bug or have an idea? Open an issue on the Five Server repository.
live-server command. The README suggests running
npm -g rm live-server before you install Five Server.
watch and ignore to narrow it.
07 Install
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