You can create a simple HTTP server in Node.js using the built-in http
module — no external libraries required. Here's a minimal example:
✅ Step-by-Step: Create a Simple HTTP Server
🔍 How It Works:
-
http.createServer()
creates an HTTP server and defines how it handles requests (req
) and responses (res
). -
res.end()
sends the response to the client. -
server.listen()
starts the server on a specific port (e.g., 3000).
✅ To Run the Server:
-
Save the code as
server.js
-
Run in your terminal:
-
Visit http://localhost:3000 in your browser — you’ll see "Hello, world!"