Hello Dev Community! 👋
It is officially Day 35 of my journey to master the MERN stack! Today, I advanced into the next vital phase of Prashant Sir's (Complete Coding) Node.js masterclass, moving away from local files to build something incredible: My very first native web server from scratch!
Up until yesterday, our scripts ran and closed instantly. Today, I engineered a server that stays alive, continuously listening for connections from the internet.
🧠Key Learnings From Node.js Lecture 3 (HTTP Module)
Understanding how computers talk to each other across network lines is a huge breakthrough. Here is the technical breakdown of what I mastered today:
1. The Core http Module
I explored Node's native http utility, which allows us to handle internet data packets. By using http.createServer(), we spin up an active server instances that handles a standard callback function with two powerful arguments:
-
req(Incoming Message): Contains all the data coming from the client/browser (like the URL path or headers). -
res(Server Response): The tool we use to send data back to the user (like headers, HTML, or JSON).
2. Port Allocation & server.listen()
I learned that a server needs a specific gateway or "door number" to communicate on a machine. I configured my server to listen on a local port (like 3000 or 8000) using server.listen(port, () => {}).
javascript
const http = require("http");
const server = http.createServer((req, res) => {
res.end("Hello from my Day 35 custom server!");
});
server.listen(8000, () => {
console.log("Server is live and listening on port 8000");
});
Top comments (0)