A web server is a program that receives requests from clients (browsers) and sends back responses.
Node.js makes this easy using its built-in http module, without any external libraries.
The http module allows Node.js to handle web requests and responses.
Use createServer() to define how the server should respond to requests.
Here:
request contains client information
response is used to send data back
200 indicates a successful request
A port is a communication endpoint. The server waits for requests on a specific port.
Save the file as server.js
Open terminal and run:
Uses non-blocking I/O
Handles multiple requests efficiently
Requires no external packages
Lightweight and fast
Learning Node.js basics
Testing APIs
Simple backend services
With just a few lines of code, Node.js can act as a fully functional web server.
This simplicity, combined with high performance, makes Node.js ideal for building scalable network applications.
Open a browser and visit:
Take quizzes related to this topic and see where you stand!
Start Quiz Now