As a developer, you usually have to spin up a simple web server from a local folder in your system. Configuring and running a full blown web server like Nginx or Apache simply takes too much time, so much that it will make your workflow completely unproductive.
In this article, you'll find quick ways to start a local HTTP server, depending on your operating system and programming language you're working with.
Mongoose - instant local HTTP Server
Mongoose is a event-driven non-blocking APIs networking library for C/C++. The library has been actively developed since 2004, used by vast number of open source and commercial products, mostly embedded platform.
While being a networking library itself, Mongoose homepage also host binaries for Windows, MacOS and Linux that allows for quick server start up.
Mongoose executable does not depend on any external library or configuration. This makes Mongoose perfect for all kinds of demos, tests, file sharing, and API testing.
In order to start a server, you only need to drop its executable into a folder/directory and run it. The server will be instantly started on port 8080.
Also, if you need to install the HTTP server as a service, look no further, Mongoose has that feature integrated.
If you need more options, you can configure it by creating a
mongoose.conf file with respective options can be created in the same directory where executable lives. The configuration details can be found at Mongoose homepage.
Nginx - the big name but tiny-sized
Believe it or not, despite being a big name on the market, Nginx entire build weights only under 2MBs in size, which makes it eligible for the "lightweight" category of web servers.
If you're using Windows, just head over to nginx download page and get the zip package. Once extracted, double clicking
nginx.exe will immediately spin up a local HTTP server at port 80.
Node.js local HTTP server
If you have Node.js installed, you can use
npm to get an additional
http-server package to quickly spin up a local HTTP server.
Code language: Bash (bash)
npm install -g http-server
Once the installation is done, spinning up a local HTTP is super easy. You just have to run
http-server inside the folder you want to expose.
http-server will listen on port 8080, but you can change it using the
-p flag if you want (see more options by running
Python local HTTP server
If you're using Ubuntu or Debian, there's a high chance you already had Python 3 installed.
In this case, you can use Python's
http standard library to spin up a local HTTP server by running the following command inside any directory you want to expose.
Code language: Python (python)
python -m http.server 8080
Feel free to replace
8080 with any other port of your choice.
Chrome-based local HTTP server
Google Chrome is now the most popular browser in the world. Its functionality can be extended through extensions.
There is an extension named Web Server for Chrome that helps you spin up a simple local HTTP server to serve static files and HTML content.
In addition to listening to connections at certain port, the Chrome-based local HTTP server can also runs in the background and prevent computer from sleeping, which makes it perfect for small development tasks.
Web Server for Chrome can be installed on all Chromium-based browsers which supports extensions. Once installed, it can either be opened by accessing
chrome://apps/ from browser, or Windows Settings > Chrome Apps > Web Server for Chrome.
Simple web-server - tiny HTTP server with a GUI
Simple web-server is a small application that expose a folder to a local HTTP server.
It only works in Windows and weights only 330 KB, which makes it perfect for serving HTML sites on the go.
Simple web-server works right out of the box without administrative privileges. Uninstalling the app can simply be done by deleting the executable.
Although the tool doesn’t integrate a help manual, all of its features are highly intuitive and you can easily get an idea of how it works.