Creating Web Server in Node.js With HTTP Module
Creating Web Server in Node.js With HTTP Module
SERVER IN NODE.JS
WITH HTTP MODULE
CREATING A BASIC HTTP
SERVER
Learning back-end development is understanding how to set up a
server that can handle requests and send responses. Node.js’s http
module provides the ability to create such a server easily.
Import the http module, then use http.createServer() to set up a basic
server.
The server uses a callback function to handle each request, where req
represents the incoming request, and res represents the outgoing
response.
EXAMPLE
Here’s a simple HTTP server that listens on port 5000 and sends a
“Hello, World!” response to every request.
RETURNING DIFFERENT
TYPES OF CONTENT
Understand how to respond with different types of content (plain text,
JSON, HTML) and how to set the appropriate Content-Type headers for
each. This is a key skill in building dynamic and interactive web
applications.