June 22, 2026 · by Meegrow Labs

How to Build a Web Server in 10 Lines (Node.js)

You have heard the phrase “web server” a hundred times. It sounds like something only big companies with huge data centres can run. But the truth is much friendlier.

In this lesson we are going to build a web server together. Your very own one. And it takes only about ten lines of code.

To build a web server, you write a small Node.js program that uses Express to listen for visitors and send each one a reply — it is real, working code that fits in roughly ten lines.

What does a web server actually do?

Think of a tiny shop counter. Someone walks up to visit. The person behind the counter answers. The visitor gets a reply and walks away happy.

A web server does the same thing. It waits for visitors to ask for a page, and then it replies. Your code decides what reply each visitor gets.

So the whole job is two steps: wait, then reply. Someone visits your address, your server answers their request, and they get a reply back. That is it.

Why use Express to build a web server?

Node.js can build a web server on its own, but the code is fiddly. Express is a small helper library that handles the boring parts for you, so you can focus on what reply to send.

With Express, sending a reply to each visitor takes one short line. That is why beginners reach for it first — it keeps the code tiny and readable while you are still learning. If you have not met npm or installed packages yet, the free Zero to AI Hero course walks you through it step by step before this point.

What does the code look like?

Here is the core of a hello-world server. Save it as a file called server.js:

const express = require('express')
const app = express()

app.get('/', (req, res) => {
  res.send('Hello world')
})

app.listen(3000, () => {
  console.log('Server is live on port 3000')
})

Three lines do the real work, and they are worth understanding:

  • app.get runs whenever someone visits a page.
  • res.send is the reply that visitor receives.
  • app.listen keeps the server open and waiting.

Just a few lines, and it is alive. The same idea — wait, then reply — powers huge sites used across India every day, from a UPI payment screen to a Flipkart product page.

How do I run my web server?

Once the file is saved, open your terminal in the same folder and run the file with Node.js:

node server.js

Press enter. You should see your message print out:

Server is live on port 3000

Your server is now live and listening. It will keep running and replying to every visit until you stop it. In the next lesson we open it in a browser and actually see the reply.

Why is this such a big deal?

Because ten lines just gave you a live server. You did not rent a data centre or learn a year of theory — you wrote a file and ran it.

This is the real foundation of the web. The same small idea scales from a weekend side project to a funded startup. It is tiny, it is real, and it is yours.

Key takeaways

  • A web server simply waits for a visitor to ask for a page, then sends back a reply.
  • You can build a web server in about ten lines using Node.js and Express.
  • app.get handles a visit, res.send sends the reply, and app.listen keeps the server open.
  • Run it with node server.js and your server goes live and listening.
  • This small pattern is the same one behind the biggest websites you use — keep going with the free Zero to AI Hero course to run and grow your server next.

🚀 Take the full free course: Zero to AI Hero — learn to build with AI from scratch. New lessons daily, in Hindi & English.

Meegrow Labs

We help India go from zero to AI hero — learn to use & build with AI from scratch, in Hindi & English. Start the free course →

Want to actually learn this?

151 free 2-minute lessons — from "what's a file?" to building with AI.

▶ Start the free course