Python’s http.server (or SimpleHTTPServer for Python 2) is a great way of serve the contents of the current directory from the command line:
python -m http.server
However, as far as web servers go, it’s very slooooow…
It behaves as though it’s single threaded, and occasionally causes timeout errors when loading JavaScript AMD modules using RequireJS. It can take five to ten seconds to load a simple page with no images.
What’s a faster alternative that is just as convenient?
http-server for node.js is very convenient, and is a lot faster than Python’s SimpleHTTPServer. This is primarily because it uses asynchronous IO for concurrent handling of requests, instead of serialising requests.
Installation
Install node.js if you haven’t already. Then use the node package manager (
npm) to install the package, using the-goption to install globally. If you’re on Windows you’ll need a prompt with administrator permissions, and on Linux/OSX you’ll want tosudothe command:This will download any required dependencies and install
http-server.Use
Now, from any directory, you can type:
Path is optional, defaulting to
./publicif it exists, otherwise./.Options are [defaults]:
-pThe port number to listen on [8080]-aThe host address to bind to [localhost]-iDisplay directory index pages [True]-sor--silentSilent mode won’t log to the console-hor--helpDisplays help message and exitsSo to serve the current directory on port 8000, type: