Mongoose – a tiny, one-file http server. Absolute love.

July 29th, 2015 | Permalink

The story is this: I needed a tiny web server to provide with some front-end only website. The website used json loaded via AJAX calls, so was intended to be running on a server. One could not just open the index.html file in your browser.

But I needed the end user to be able to run my website anyway. Since I was pretty sure they will be running it on Windows I needed something like this:

  • It should be a single executable file. To not litter the project directory with tons of files
  • It should be portable. No installation. No complex, env-dependent configuration.
  • It should support command prompt
  • I should be able to specify the root (document) folder which files will be served. I didn’t need any CGI. Just files seved over HTTP correctly.
  • All of the files should be served with correct headers
  • I had not security concern since it was intended for local use only.

Now right, I know one can run server via node, ruby and even php. But again that was not an option, as well as assembling some portable nginx/apache etc.

After several unsuccessful tries I found Mongoose. It’s free (well it’s non-CGI edition is) and it gave me all I wanted and even more – the ability to run the browser on start. And it is pretty easily configurable via command line parameters. It even supports some rewrites!

..and then I gave the end user a bat file to run it:

taskkill -im mongoose.exe
start "Mongoose" "%~dp0\server\mongoose.exe" -listening_port 8085 -document_root "%~dp0\www"

And now sometimes I still use it as a way to quickly test my front-end stuff.