I wanted a simple webserver that simply serves the files in a directory. There are plenty of options, but I wanted one that doesn’t depend on other programs (like NPM/NPX/Python/…). So I built one.
I proudly present serve! A simple webserver that can be started from the command line.
Just do this:
cd navigate/to/the/folder serve
And that’s it!
A browser window will open, showing the
index.html or a file list.
Another feature is the auto-reload for for file changes.
The approach is pretty naive (polling and creating a hash over file modification dates), but it works.
The full customizability is:
serve --address="localhost:3000" --folder="/my/folder" --auto-refresh="false" --open="false"
- Cross-Origin Resource Sharing (CORS) restrictions: Browsers block access attempts to other files from
- Cookies and Local Storage: May doesn’t behave as intended, also because of the Same origin policy.
- Broken links: Links starting with
/assets/style.css) don’t work as needed.
file://URL often triggeres distracting security warnings.
All of this leads to big differences between development and production environment. And that’s why a simple webserver comes in handy, and also that it doesn’t depend on other toolchains. The auto-refresh helps with faster iterations.