Creating Routes and Handling Requests with Express

Learning web development in public. Writing simple, real-world explanations about web development concepts. Helping beginners understand why things work, not just how.
Search for a command to run...

Learning web development in public. Writing simple, real-world explanations about web development concepts. Helping beginners understand why things work, not just how.
No comments yet. Be the first to comment.
Every day, millions of users upload photos, videos, stories, and reels to Instagram. From a user's perspective, the process appears simple: select media, apply filters, add a caption, and tap "Post."
Building Offline-First Messaging Apps: How Messages Work Without Internet Modern messaging applications have transformed the way people communicate. Whether it's chatting with friends, collaborating w
In this article we'll explore about the Expo Router and React Navigation and answer which one to use in 2026. If you build mobile apps using React Native, one thing becomes obvious very quickly: Navig

Modern mobile apps are no longer just a collection of screens connected together. Apps like Instagram, WhatsApp, Uber, and Netflix operate at massive scale with millions of users, real time systems, o
In this article we'll be exploring react.js and the things of react.js that makes it popular and stand out among other libraries ( no fight over library vs framework ). We'll go through: What problem

Shkaai
68 posts
When working with Node.js, writing everything using the built-in http module can quickly become complex. This is where Express.js comes in. It simplifies backend development and makes handling routes and requests much easier.
Let’s understand this step by step.
Express.js is a minimal and flexible web framework for Node.js.
It helps you:
Create servers easily
Handle routes (URLs)
Manage requests and responses
Build APIs quickly
Instead of writing long and repetitive code using Node’s http module, Express gives you simple methods to handle everything.
Without Express, creating a server looks like this:
const http = require('http');
const server = http.createServer((req, res) => {
if (req.url === '/about') {
res.end('About Page');
}
});
server.listen(3000);
As your application grows, this becomes hard to manage.
With Express, the same thing becomes:
const express = require('express');
const app = express();
app.get('/about', (req, res) => {
res.send('About Page');
});
app.listen(3000);
Express provides:
Cleaner syntax
Easy routing
Built-in middleware support
Better organization of code
First, install Express:
npm init -y
npm install express
Now create a file app.js:
const express = require('express');
const app = express();
// basic route
app.get('/', (req, res) => {
res.send('Welcome to Express Server');
});
// start server
app.listen(3000, () => {
console.log('Server running on port 3000');
});
Run the server:
node app.js
Open browser:
http://localhost:3000
You will see your response.
GET requests are used to fetch data from the server.
app.get('/users', (req, res) => {
res.send('List of users');
});
You can also access query data:
app.get('/search', (req, res) => {
const keyword = req.query.keyword;
res.send(`Searching for ${keyword}`);
});
POST requests are used to send data to the server.
Before handling POST data, remember to enable JSON parsing
app.use(express.json());
app.post('/users', (req, res) => {
const user = req.body;
res.send(`User received: ${JSON.stringify(user)}`);
});
You can test POST requests using tools like Postman or frontend forms.
Express provides different methods to send responses:
res.send('Hello World');
res.json({ message: 'Success' });
res.status(200).send('OK');
res.sendFile(__dirname + '/index.html');
These methods make it easy to control what the client receives.
Express.js is a lightweight framework built on Node.js
It simplifies server creation and routing
You can easily handle GET and POST requests
Request data can be accessed using req
Responses are sent using res methods
It helps organize backend code in a clean and scalable way
Express.js removes much of the complexity involved in using Node.js directly. Instead of manually handling request URLs and responses, you define clear routes using simple methods like app.get() and app.post(). This makes your code easier to read, maintain, and scale. By learning how to create routes and handle requests in Express, you take an important step toward building real-world backend applications such as REST APIs, authentication systems, and full-stack projects.