Setting Up a Local Web Server using Node.js

Setting Up a Local Web Server using Node.js

When you're working on a site or web app, there will be times when you need to test files as if they were being served from a remote web server, similar to how they are when you browse the web normally.

When you're working on a site or web app, there will be times when you need to test files as if they were being served from a remote web server, similar to how they are when you browse the web normally.

If you don't have your own server, or just want to test files locally, you can set up a local web server on your computer to simulate one to do the job, and this tutorial is here to teach you how.

Install Node and NPM

To run our local web server, we will be using Node.js, a JavaScript runtime.

  1. Visit the official Node.js website to get the installer.
  2. After it downloads, run the installer until the end.
  3. Restart your computer to ensure the changes can take effect.

The Node.js installer should have also installed NPM for you. To confirm that you have installed both properly, you'll need to open Windows Command Prompt if you're on Windows, or Terminal if you're on Mac or Linux.

To check if you installed node:


    node -v

To check if you installed NPM:


    npm -v

If both of these commands return a version number, you're good to go.

Install http-server

Now that we have Node and NPM installed, we can move forward and install the Node package called http-server, which is a simple zero-configuration HTTP server that serves up static files.


    npm install http-server -g

This command will install it on your computer globally so you can use it anywhere.

Therefore, after you have navigated to your folder via the command line, start the server using this command:


    http-server -o

If successful, you should see something similar to this:


    http-server -o
    Starting up http-server, serving ./
    Available on:
        http://192.168.1.8:8080
        http://127.0.0.1:8080
    Hit CTRL-C to stop the server

Upon seeing this, a browser window should have opened for you automatically, but if not, you can manually head to <a href="http://127.0.0.1:8080" target="_blank">http://127.0.0.1:8080</a> to see the folder that you used the command on being served.

Thanks for reading ❤

node-js web-development

What's new in Bootstrap 5 and when Bootstrap 5 release date?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Random Password Generator Online

HTML Color Picker online | HEX Color Picker | RGB Color Picker

How to Hire Node.js Developers And How Much Does It Cost?

A Guide to Hire Node.js Developers who can help you create fast and efficient web applications. Also, know how much does it cost to hire Node.js Developers.

Top Node.js Development Companies and Expert NodeJS Developers

A thoroughly researched list of top NodeJS development companies with ratings & reviews to help hire the best Node.JS developers who provide development services and solutions across the world. List of Leading Node.js development Service Providers...

Hire Node JS Developer from Expert Node JS Development Company

NodeJS Development Company-Hire Node JS developer from the most prominent NodeJS development company, Mobiweb and get remarkable Node.js app development services.

Main Reasons of Using Node JS for Your Web Application Development

You have to hire Node JS developer from prestigious and expert Node JS development company Mobiweb Technologies. They are tech enthusiasts with new and latest programming ideas, web development technologies and industry trends.

How to Hire Node JS Developers and How Much Does It Cost.

The developer community has witnessed the boom of Node.js in the past years. The year 2017 brought Node JS in limelight with the number of projects being developed in Node.JS. The high demand and the immense scope of development withdrew...