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.
The Power of Help Desk Software: An Insider's Guide My Journey into Customer Support Chaos…
Building a Human Handoff Interface for AI-Powered Insurance Agent Using Parlant and Streamlit Human handoff…
Knowing how to check your iPad’s battery health might sound straightforward, but Apple has made…
The Challenges of Health Financing in Transition: A Closer Look at the Social Health Authority…
Tech News Looking for affordable yet impressive Diwali gifts? These top five tech gadgets under…
The Ever-Changing Landscape of Cybersecurity: A Weekly Update Oct 13, 2025 - By Ravie Lakshmanan…