Open In App

How to Install Node.js on a Webserver ?

Last Updated : 10 Jul, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Node.js is a powerful, lightweight, and efficient runtime for executing JavaScript code on the server side. It is particularly well-suited for building scalable network applications. Installing Node.js on a web server enables developers to run server-side JavaScript, host web applications, and serve dynamic content. This article provides a step-by-step guide on how to install Node.js on a web server.

Steps to Install Node.js on a Webserver

Step 1: Download and install NodeJS

Use this link to download the latest version of Node.js and then install it on your local machine using all the default options.

Step 2: Install the HTTP-server package from npm

You can run the Node.js application directly from a command prompt or a command-line window. Now, you need to install the HTTP-server module, it should be installed as a global npm package.

Open the command prompt/command line and enter the following command:

npm install -g http-server

Step 3: Start a web server from a directory containing static website Files

Now, after installing the module, you need to start the server. For that, you first need to change to the directory containing your static web files (HTML/CSS/JS, etc). Use the cd command for that.

In a command prompt/command line, enter the following command:

cd projects\node

Now, start the server with the following command:

http-server

Now, you will see the following output on screen:

Step 4: Browse to your local website with a browser

Open any browser and go to http://localhost:8080/ (URL which we get from as output after we execute the above command). Now we can see our local website running, this is how we can install Node.js on a web server.



Next Article

Similar Reads