𝗗𝗮𝘆 𝟯𝟱 𝗼𝗳 𝗟𝗲𝗮𝗿𝗻𝗶𝗻𝗴 𝗠𝗘𝗥𝗡 𝗦𝘁𝗮𝗰𝗸
I built my first native web server today.
In my Node.js masterclass with Complete Coding, I moved beyond local scripts. My previous code ran and stopped. Today, I built a server that stays active. It listens for internet connections.
I learned how computers communicate across networks.
Here are the two main concepts I mastered:
The http Module I used the native http utility to handle data. I used http.createServer() to start a server. This function uses two arguments: • req (Request): This holds data from the browser, like URLs or headers. • res (Response): This lets me send data back to the user, such as HTML or JSON.
server.listen() A server needs a specific port to communicate. I set my server to listen on a local port like 8000. This creates a gateway for connections.
Code implementation:
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"); });
Source: https://dev.to/ali_hamza_589ec7b3eb6688d/day-35-of-learning-mern-stack-ldn