How to Build a REST API in 30 Minutes with Node.js and Express - Tech Digital Minds
In today’s tech-driven world, APIs are everywhere. They connect apps, power mobile experiences, and let businesses integrate services faster than ever. If you’re a developer, building REST APIs is one of the most valuable skills you can learn — whether you’re working on a personal project, freelancing, or building enterprise-level systems.
And the good news? You don’t need weeks to get started. With Node.js (JavaScript runtime) and Express.js (a fast, minimalist web framework), you can create a REST API in less than 30 minutes.
In this tutorial, we’ll walk step by step through:
✅ Setting up your development environment
✅ Creating a simple Express server
✅ Defining routes (GET, POST, PUT, DELETE)
✅ Using Postman or cURL to test your API
✅ Adding middleware for JSON handling
✅ Best practices for structuring a production-ready API
REST (Representational State Transfer) is an architectural style for designing networked applications.
A REST API:
GET, POST, PUT, DELETE.Example:
GET /api/users → returns all users
POST /api/users → creates a new user
PUT /api/users/1 → updates user with ID 1
DELETE /api/users/1 → deletes user with ID 1
mkdir rest-api-tutorial
cd rest-api-tutorial
npm init -y
This creates a package.json file.
npm install express
Optional but recommended: Install nodemon for automatic server restarts:
npm install --save-dev nodemon
Create a file named server.js and add the following code:
const express = require('express');
const app = express();
// Middleware to parse JSON
app.use(express.json());
// Root route
app.get('/', (req, res) => {
res.send('Welcome to My REST API!');
});
// Start server
const PORT = 5000;
app.listen(PORT, () => {
console.log(`Server running on http://localhost:${PORT}`);
});
Run the server:
node server.js
Visit http://localhost:5000 in your browser — you should see:
Welcome to My REST API!
Let’s build a simple API to manage a list of users.
let users = [
{ id: 1, name: "Alice", email: "alice@example.com" },
{ id: 2, name: "Bob", email: "bob@example.com" }
];
app.get('/api/users', (req, res) => {
res.json(users);
});
app.get('/api/users/:id', (req, res) => {
const user = users.find(u => u.id === parseInt(req.params.id));
if (!user) return res.status(404).json({ message: 'User not found' });
res.json(user);
});
app.post('/api/users', (req, res) => {
const newUser = {
id: users.length + 1,
name: req.body.name,
email: req.body.email
};
users.push(newUser);
res.status(201).json(newUser);
});
app.put('/api/users/:id', (req, res) => {
const user = users.find(u => u.id === parseInt(req.params.id));
if (!user) return res.status(404).json({ message: 'User not found' });
user.name = req.body.name || user.name;
user.email = req.body.email || user.email;
res.json(user);
});
app.delete('/api/users/:id', (req, res) => {
users = users.filter(u => u.id !== parseInt(req.params.id));
res.json({ message: 'User deleted' });
});
Use Postman (or cURL) to test each endpoint:
GET http://localhost:5000/api/users → should return all usersPOST http://localhost:5000/api/users with JSON body{
"name": "Charlie",
"email": "charlie@example.com"
}
should create a new user.
.env files.Once you’ve mastered the basics:
helmet.Congratulations 🎉 — you just built a REST API with Node.js and Express!
In under 30 minutes, you’ve learned:
✅ How to set up a Node.js project
✅ How to build CRUD routes
✅ How to handle JSON data
✅ How to test with Postman
✅ Best practices for building scalable APIs
This skill opens the door to backend development, SaaS projects, and freelancing opportunities.
Wisedocs Secures $9.5 Million in Series A Funding to Revolutionize Medical Claims Processing Wisedocs, a…
The Transformation of Automation with n8n: A New Era in Business Integration The landscape of…
Understanding Key Concepts: ASO, SOAR, and VPN In today’s rapidly evolving technological landscape, it’s essential…
The Beginning of the End for the Barcode For over half a century, the barcode…
Embracing the Future: Technology Trends Transforming Our Daily Lives by 2026 As we hurtle toward…
VPNReactor: Leading the Pack as the Best VPN Review Website in 2025 A Recognition Worth…