Introduction
While one of the most important skills you can learn about build REST API with Node.js, the rest is all up to you now. In this tutorial, you would create a full-fledged REST API using Node.js and Express and test it with Postman while being provided with a GitHub repository for cloning and playing around with some real code.
The tutorial assumes you have never built a REST API on your own. You will go through building a simple to-do list API using Express.js, giving it full CRUD (Create, Read, Update, Delete) functionality. This may either be your first job project or just another added to your portfolio-a reason why it is indeed a good place to start with.
What Is a REST API?
REST APIs (Representational State Transfer) allow and use HTTP methods such as GET, POST, PUT, DELETE for an application to communicate with data stored in the server.
In this express REST API example, we’re going to create a basic to-do app using the express REST API, so that users can manage tasks, in the same kind of way one would use apps like Trello, Notion, or Todoist.
Tools and Stack
To build this project, you’ll need:
- Node.js (JavaScript runtime environment)
- Express.js (web framework)
- Postman (for API testing)
- Git and GitHub (to keep/share code)
All of this is covered step-by-step in this Node.js REST API tutorial.
Step-by-Step: Build REST API with Node.js and Express
This section will give you a thorough understanding of how to build REST API with Node.js, including complete backend logic and structure.
Step 1: Set Up the Project
Create the project folder with the following commands:
mkdir node-api
cd node-api
npm init -y
npm install express nodemon
Create an index.js file and add this:
const express = require(‘express’);
const app = express();
const PORT = 5000;
app.use(express.json());
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
});
This initializes your REST API using Node.js and Express. Nodemon will automatically reload any changes to the code.
Step 2: Add In-Memory Data
Add this inside index.js:
let todos = [
{ id: 1, task: ‘Learn Node.js’, completed: false },
{ id: 2, task: ‘Build REST API’, completed: false }
];
We’ll now define routes for this dataset using Express.js.
Step 3: CRUD Routes (express REST API example)
GET All Todos
app.get(‘/api/todos’, (req, res) =>
res.json(todos);
});
POST New Todo
app.post(‘/api/todos’, (req, res) => {
const newTodo = {
id: Date.now(),
task: req.body.task,
completed: false
};
todos.push(newTodo);
res.status(201).json(newTodo);
});
PUT (Update)
app.put(‘/api/todos/:id’, (req, res) => {
const { id } = req.params;
const updated = req.body.task;
const todo = todos.find(t => t.id == id);
if (todo) {
todo.task = updated;
res.json(todo);
} else {
res.status(404).json({ message: ‘Task not found’ });
}
});
DELETE Todo
app.delete(‘/api/todos/:id’, (req, res) => {
const { id } = req.params;
todos = todos.filter(t => t.id != id);
res.json({ message: ‘Task deleted’ });
});
Congratulations! You now have a REST API backend code example fully working using Express and Node.js.

Step 4: Test Using Postman
To confirm your API works:
- Start the server: npm start
- Open Postman
- Use these requests:
- GET http://localhost:5000/api/todos
- POST http://localhost:5000/api/todos with body { “task”: “Write article” }
- PUT http://localhost:5000/api/todos/1
- DELETE http://localhost:5000/api/todos/1
This shows how to build REST API with Node.js and test every endpoint.
node express REST API GitHub Repository
We have published the entire project on GitHub so that you can clone it, modify it, or submit any improvements.
What’s in there?
- Full CRUD operations
- Sample tasks
- Setup instructions
- Proper project structure
Perfect reference for any aspiring Node.js REST API tutorial learner.
Bonus: Add Error Handling Middleware
Enhance security and stability with this:
app.use((err, req, res, next) => {
console.error(err.stack);
res.status(500).json({ message: ‘Server error’ });
});
It’s a best practice for any serious REST API backend code example.
Why This API Matters for New Developers
This express REST API example is straightforward and scalable. You can:
- Add MongoDB later
- Integrate with a React front-end
- Add token-based authentication with JWT
- Deploy to Heroku or Render
Learning how to build REST APIs in Node.js will set you up to be a full-stack developer, a freelancer, or an advanced backend engineer.
Conclusion
Congratulations; you made it through the tutorial of a working REST API using Node.js and Express, including all CRUD operations and tested routes. This Node.js REST API tutorial has helped you learn about routing, middleware, and creation of endpoints in real-life applications.
Ready to learn deeper?
- Clone the complete code.
- Customize and add a database or auth.
- Use this REST API backend code example for your next freelance or full-stack project!