Learning backend development might seem overwhelming at first — databases, APIs, routing, deployment — where do you even start?
Well, here's some good news: You can build your first backend API using Node.js and Express in just 15 minutes. And by the end of this post, you'll have your own working API ready to go!
Let’s jump right in 👇
🚀 What We're Building
A simple Books API with 3 routes:
-
GET /books
— List all books -
POST /books
— Add a new book -
GET /books/:id
— Get a book by ID
🛠️ Step 1: Setup Your Project
mkdir books-api
cd books-api
npm init -y
npm install express
Create a file named index.js.
🧠 Step 2: Create a Simple Express Server
const express = require('express');
const app = express();
const port = 3000;
app.use(express.json()); // for parsing JSON
app.listen(port, () => {
console.log(`Server is running on http://localhost:${port}`);
});
Run the server:
node index.js
📚 Step 3: Add Book Routes
let books = [
{ id: 1, title: 'Clean Code' },
{ id: 2, title: 'The Pragmatic Programmer' },
];
// GET all books
app.get('/books', (req, res) => {
res.json(books);
});
// GET a book by ID
app.get('/books/:id', (req, res) => {
const book = books.find(b => b.id === parseInt(req.params.id));
if (!book) return res.status(404).send('Book not found');
res.json(book);
});
// POST a new book
app.post('/books', (req, res) => {
const book = {
id: books.length + 1,
title: req.body.title,
};
books.push(book);
res.status(201).json(book);
});
Now you can:
Use Postman or Insomnia to send GET, POST requests
Try it out at http://localhost:3000/books
🌱 What You Just Learned
- How to set up an Express server
- Basic routing in Node.js
- Handling JSON input
- Working with dynamic route parameters
This is the first step toward building real-world backend applications.
🎓 Want to Go Deeper?
This was just a glimpse into what you can build with Node.js. If you enjoyed this, I've created a full all-in-one backend development course that covers:
✅ Node.js, Express, TypeScript
✅ MongoDB, PostgreSQL, Mongoose
✅ REST & GraphQL APIs
✅ Authentication, Stripe, Docker
✅ GitHub Actions, CI/CD, and more
🎁 Grab the course with two options:
💸 Support the course (only $9.99):
https://www.udemy.com/course/express-typescript-nodejs-mongodb-more-the-real-path/?couponCode=93AC6D647A1F2AD85580
🙌 Get it free (for early learners):
https://www.udemy.com/course/express-typescript-nodejs-mongodb-more-the-real-path/?couponCode=FA39975BFDE32309993C
Top comments (5)
Is you created an API For Develoepr. Any API
Cool 🌟
Simple and cool
Pretty cool seeing all the basics broken down like this-it's less scary to jump in now.
Some comments may only be visible to logged-in visitors. Sign in to view all comments.