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

1

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

Billboard image

Deploy and scale your apps on AWS and GCP with a world class developer experience

Coherence makes it easy to set up and maintain cloud infrastructure. Harness the extensibility, compliance and cost efficiency of the cloud.

Learn more

Top comments (0)

Cloudinary image

Optimize, customize, deliver, manage and analyze your images.

Remove background in all your web images at the same time, use outpainting to expand images with matching content, remove objects via open-set object detection and fill, recolor, crop, resize... Discover these and hundreds more ways to manage your web images and videos on a scale.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay