DEV Community

Cover image for How to Setup a Simple HTTP Server/ Local Web Server with NodeJS
Pankaj Kumar
Pankaj Kumar

Posted on

How to Setup a Simple HTTP Server/ Local Web Server with NodeJS

In this article, I am going to explain to you how to set up a simple HTTP web server on local machine using NodeJS. http-server npm package is used to run the web server, Its a single step task for serving static files on browser.

Install http-server npm package
Install the http-server globally on machine using the node package manager (npm) command-line tool, this will allow you to run a web server from anywhere on your computer.

Run the below command on comman line


npm install -g http-server

Enter fullscreen mode Exit fullscreen mode

Start web server
Move to project folder where static files are kept with below command


cd /Desktop/projects/demo/sample-bootstrap

Enter fullscreen mode Exit fullscreen mode

start web server with below command


http-server

Enter fullscreen mode Exit fullscreen mode

Above command will return Urls of hosted files which can be used to check the hosted files on browser.

Image description

Check the hosted files
After running the last command the static files are hosted on the above 2 links provided, Type http://localhost:8080 on your browser URL and you will see your local website.

Conclusion
http-server is a simple, zero-configuration command-line http server. It is powerful enough for production usage, but it's simple and hackable enough to be used for testing, local development, and learning.

Click here to find Sample Applications on different frameworks of Javascript.

Let me know your thoughts over email demo.jsonworld@gmail.com. I would love to hear them and If you like this article, share with your friends.

This article is originally posted over jsonworld

Top comments (0)