DEV Community

Cover image for Build Your First REST API with Node.js and Express (in 15 Minutes)
ayka.code
ayka.code

Posted on

Build Your First REST API with Node.js and Express (in 15 Minutes)

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

Enter fullscreen mode Exit fullscreen mode

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}`);
});

Enter fullscreen mode Exit fullscreen mode

Run the server:

node index.js

Enter fullscreen mode Exit fullscreen mode

📚 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);
});

Enter fullscreen mode Exit fullscreen mode

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)

Collapse
 
aquascript-team profile image
AquaScript Team

Is you created an API For Develoepr. Any API

Collapse
 
aquascript-team profile image
AquaScript Team

Cool 🌟

Collapse
 
marmeden profile image
eneasmarin

Simple and cool

Collapse
 
nevodavid profile image
Nevo David

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.