Saturday, December 9, 2017

Setting up a simple HTTP Server for local web development

See also watch-http-server

1. Install NodeJS from https://nodejs.org

2.  Install http-server npm package

npm install -g http-server

3. From command line, change to the directory containing your static web files (e.g. html, javascript, css etc) in the command line window, e.g:

cd \temp\website

4. Start the server from the website directory with following command line command.
http-server

Or run it with more more options
http-server [path] [options]

See http-server

5. The http-server will start and print the local http address where the website can be reached. It is typically http://localhost:8080. Open your browser and go to the address http://localhost:8080 and you should see the index file in your web site directory from Step 3.

Another implementation of http-server is watch-http-server

It works similarly to http-server but automatically reloads the webpage when it changes on disk. This is very useful during developement.