Setting Up Node.js and Creating a Basic HTTP Server: A Beginner's Guide
Sudhanshu Gaikwad
Posted on July 4, 2024
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:
- Open your terminal or command prompt.
- Type
node -v
to check ifNode.js
is installed.
c:use\xyz\abc> node -v
v14.17.3
c:use\xyz\abc> npm -v
6.14.13
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");
});
Step 3: Running the Server
c:use\xyz\abc\nodebackend>node server.js
The server is starting at 5050
Step 4: Access the Server on browser
- Open a web browser or use a tool like Postman.
- Type in the browser URL Box http://localhost:5050 in your browser.
- You will see the response "Hello It is a testing..!" displayed in the browser.
💖 💪 🙅 🚩
Sudhanshu Gaikwad
Posted on July 4, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
beginners Learn how to isolate CSS with Shadow DOM and Slots in a gallery web component (Learn Modulo.js - Part 5 of 10)
September 27, 2024
beginners Learn template filters and state binding to quickly build a button designer tool (Learn Modulo.js - Part 4 of 10)
September 23, 2024