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.
Top comments (0)