Many Options to Run a Local Static Server

Jair Reina
The Startup
Published in
5 min readDec 29, 2020

While developing applications, learning to use a library or just testing out something quick, you might encounter the need to host your files in a “static” server — meaning that you just need an HTTP server to serve files as-is from a directory — . Nowadays, there are several simple options to get a static server running quickly, and that’s what I’m covering in this article.

For all of the options below that use the command line, I’m assuming that you already entered the folder where your files are located. For example, if your code is in the folder “project”

|- project
|- index.html
|- js
|- main.js

You should first enter to your “project” folder in the command line doing something like this:

cd /project

Node Based Servers

If you have NodeJS installed in your machine, there are several packages available through NPM/NPX that you can use. When you install Node, you get NPM and NPX installed as well. If you’re not familiar with NPX, here’s an article I wrote about it explaining it in detail. However, you don’t need to know the details in order to run your any of te options below.

1. Browsersync

Browsersync has been around for quite some time and it’s very popular while doing development. You can of course use it just to serve your static files by using this command:

npx browser-sync start --server

You’ll see an output like this:

[Browsersync] Access URLs:
Local: http://localhost:3000
UI: http://localhost:3001
UI External: http://localhost:3001
[Browsersync] Serving files from: ./

And the browser should automatically open the Local URL shown above.

If you want it to automatically watch for changes in your files and reload the page any time a file changes, just use the files option specifying the files you want to watch. like this:

npx browser-sync start --server --files "*.html, js/*.js"