Absolutely Simple WebServers that will save your time!


At times you would want to run a simple web server to serve static pages for trying out somethings. To run such web server on Windows  we have two simple options.

Option 1: Using Python

Python version 2.x.x comes with a pre-built script called ‘SimpleHTTPServer’ for running a Web server. You can run it using the following command

C:\>python -m SimpleHTTPServer

The web server by default listens on port 8000. You can optionally give a port number as shown below

C:\>python -m SimpleHTTPServer 8910

Here we have passed the port number as an additional parameter.

However, it can only server files from the current directory. You could modify the python script to accept the directory name as a parameter but that is out of the scope of this post.

Note:

In Python version 3.x.x the module name has changed. To get the same behavior use the following command

C:\>python -m http.server

Option 2: Using Node.js

Node.js can be used to run a simple web server. Install the package ‘http-server’ using the Node Package Manager ‘npm’ as shown below

C:\>npm install http-server -g

We are installING the Node module globally here using the ‘-g’ option. This allows us to run it from the command line.

Then, we can start the web server using the following command.

C:\>http-server

By default it listens on port 8080 and starts serving files from the current directory. We can customize these as shown below

C:\>http-server D:\site -p 8910

Here we have passed the directory name as first parameter and the port number is passed using ‘-p’ option.

For a complete details about this module visit this.

Leave a Reply

Your email address will not be published. Required fields are marked *