Running a Web server on Windows - Main image

Intermediate

Running a Web server on Windows

Here we are going to take a look at how to run a local web server on Windows using the http server module.

Žiga Triller - CodeBrainer
Žiga Triller
3 min read

This is what happened - you just started learning Web development, you covered all the basics and are now beginning to learn a high-level programming language like for example JavaScriprt. The problem is that you have written your first lines in Javascript and connected your HTML index file with your JS file, but you don't know how to test it. You can find a web hosting site but usually, they are not for free, and it is a waste of time if you only want to test your website. There are a couple of alternatives, but my favourite one is the http server module which you can use with NodeJS. 

Are you a Mac user?

Running a Web Server on a Mac

This is a solution to:

  • Running a website on Windows
  • Running a website without hosting
  • Testing your JavaScript code 

How to run a local Web server on Windows

Before you start, download and install Node JS on your computer. NodeJS is an open-source, cross-platform JavaScript run-time environment that executes JavaScript code outside of a browser. You will use NodeJS more if you decide to learn about the back-end aspect of web development. But for now, we will use NodeJS to run a local WEB server on Windows, which is a module that helps us run a website, locally on our computer. 

  • Go to Start in your windows taskbar
  • in the search field write: node.js command prompt, open it
    <Running command prompt
  • First, we have to install the http-server extension. Write: npm install http-server -g 
    Installing the http-server module
    press enter (wait for it to install)
  • After the installation is finished go to the folder where you have the index.html file from the first assignment.
  • Right click on the index.html file and Properties.
  • Copy the exact location of this file
    Checking location

Start our mentor-led course, where our mentor leads you on every step of the way. Claim your FREE trial today.

Free trial

  • Go back to the node.js command prompt window. Write: http-server and paste the exact location of the index.html file you, don’t forget the quotes and click enter. 
    Running the http-server


    Running the web server on windows

    Checking or website in browser

Congratulations as you can see you are running a local web server on windows for your page. This is a great tip for testing a website without the need for hosting. You will use this tip even when you become a hard-core web developer. Remember if you don't close the Command prompt window, be sure to click CTRL-C to stop the web server.