DEV Community

Cover image for Setting Up Node.js and Creating a Basic HTTP Server: A Beginner's Guide
Sudhanshu Gaikwad
Sudhanshu Gaikwad

Posted on

Setting Up Node.js and Creating a Basic HTTP Server: A Beginner's Guide

Introduction
In this guide, we will walk through the process of setting up Node.js on your machine and creating a basic HTTP server. Node.js is a powerful runtime environment that allows you to run JavaScript on the server side, making it ideal for building scalable and efficient web applications.
Step 1: Installing Node.js

Download Node.js:

Visit the Node.js official website.

Verify Installation:

  1. Open your terminal or command prompt.
  2. Type node -v to check if Node.js is installed.
c:use\xyz\abc> node -v
v14.17.3
c:use\xyz\abc> npm -v
6.14.13

Enter fullscreen mode Exit fullscreen mode

Step 2: Building a Basic HTTP Server
server.js

var http = require("http");

var server = http.createServer(function (req, res) {
  res.write("Hello It is a testing..!");
  res.end(); // End the response
});

server.listen(5050, () => {
  console.log("The Server is starting at 5050");
});

Enter fullscreen mode Exit fullscreen mode

Step 3: Running the Server

c:use\xyz\abc\nodebackend>node server.js
The server is starting at 5050

Enter fullscreen mode Exit fullscreen mode

Step 4: Access the Server on browser

  1. Open a web browser or use a tool like Postman.
  2. Type in the browser URL Box http://localhost:5050 in your browser.
  3. You will see the response "Hello It is a testing..!" displayed in the browser.

Image description

Top comments (0)