Creating Our First Web Server with Node.js
When we create our first Node.js application, we usually start with a web server. A web server is simply a program that listens for requests (like when you type a URL in your browser) and sends back responses (such as a web page, text, or JSON data).
Node.js makes this process easy because it comes with a built-in module called http. With just a few lines of code, we can tell Node.js to:
Listen on a port (for example, 3000).
Receive HTTP requests from the browser or another client.
Send back responses like text, HTML, or JSON.
This is the foundation of every web application — the server waits for someone to connect and then decides how to respond.