Build Your First REST API with Node.js

REST APIs are the backbone of modern web and mobile applications. If you’re learning backend development, building a REST API using Node.js is one of the best places to start.

In this guide, you’ll learn how to build your first REST API in Node.js using Express.js, with simple examples you can run locally.


Prerequisites

Before starting, make sure you have:

  • Basic JavaScript knowledge
  • Node.js installed
  • A code editor (VS Code recommended)

Check Node.js installation:

node -v
npm -v


What Is a REST API?

A REST API allows applications to communicate with each other using HTTP methods:

  • GET – Fetch data
  • POST – Create data
  • PUT – Update data
  • DELETE – Remove data

REST APIs usually return data in JSON format.


Step 1: Create a New Node.js Project

Create a folder and initialize your project:

mkdir my-first-api
cd my-first-api
npm init -y

This creates a package.json file.


Step 2: Install Required Packages

We’ll use Express.js, a popular Node.js framework.

npm install express

Optional (for auto restart):

npm install nodemon --save-dev


Step 3: Create the Server File

Create a file named index.js:

const express = require('express');
const app = express();

app.use(express.json());

const PORT = 3000;

app.listen(PORT, () => {
  console.log(`Server running on port ${PORT}`);
});

Run the server:

node index.js

Visit 👉 http://localhost:3000


Step 4: Create Your First API Route

Add a GET API:

app.get('/', (req, res) => {
  res.json({ message: 'Welcome to my first REST API!' });
});

Now open the browser:

http://localhost:3000/

You’ll see JSON output


Step 5: Create a GET API (Fetch Data)

Let’s return a list of users:

app.get('/users', (req, res) => {
  const users = [
    { id: 1, name: 'John' },
    { id: 2, name: 'Sara' }
  ];
  res.json(users);
});

URL:

GET /users


Step 6: Create a POST API (Add Data)

app.post('/users', (req, res) => {
  const user = req.body;
  res.status(201).json({
    message: 'User created',
    user
  });
});

Test using Postman or Thunder Client:

POST /users
{
  "name": "Alex"
}


Step 7: Create PUT API (Update Data)

app.put('/users/:id', (req, res) => {
  res.json({
    message: `User ${req.params.id} updated`
  });
});


Step 8: Create DELETE API

app.delete('/users/:id', (req, res) => {
  res.json({
    message: `User ${req.params.id} deleted`
  });
});


Step 9: Test Your API

You can test APIs using:

  • Postman
  • Thunder Client (VS Code extension)
  • curl command

Suggested Project Structure (Beginner)

my-first-api
│
|--- index.js
|--- package.json
|--- node_modules

As your app grows, you can separate routes, controllers, and services.

Best Practices for Node.js REST APIs

  • Use environment variables
  • Validate input
  • Use async/await
  • Add logging

Frequently Asked Questions

Is Node.js good for REST APIs?

Yes, Node.js is widely used…

Which framework is best for Node.js REST API?

Express.js is the most popular…

Can beginners learn REST API in Node.js?

Absolutely…

Top 10 AI Tools to Boost Your Productivity

Discover the best AI tools for daily work that boost productivity, save time, and make tasks easier for professionals and students.

Artificial Intelligence isn’t just buzz – it’s a powerful productivity booster you can use every day. From writing faster to managing tasks smarter, these AI tools help professionals, students, and creators work better with less effort.


1. ChatGPT – AI Assistant for Everything

What it does:
An AI you can chat with to write emails, brainstorm ideas, summarize documents, solve problems, and learn new topics.

Best for: Writing help, coding support, research, quick answers

Why it shines:

  • Natural language responses
  • Works for both casual questions and complex tasks
  • Saves hours on writing and planning

2. Grammarly – Smarter Writing

What it does:
Corrects spelling & grammar, improves tone, and suggests clearer phrasing.

Best for: Emails, reports, blog posts, social media content

Why it shines:

  • Real-time writing suggestions
  • Tone and clarity improvements
  • Easy browser & document integration

3. Notion AI – Planner + Assistant

What it does:
Built into Notion’s workspace, this AI helps you brainstorm, write content, summarize notes, and plan projects.

Best for: Daily planning, team collaboration, note summarization

Why it shines:

  • Combines task management with AI
  • Great for personal & team use
  • Helps you turn messy notes into structured content

4. Canva AI – Design Without Skills

What it does:
AI tools built into Canva generate images, write captions, suggest layouts, and improve designs.

Best for: Social posts, graphics, banners, presentations

Why it shines:

  • Drag-and-drop simplicity
  • AI text and image generation features
  • Huge library of templates

5. Otter.ai – Smart Meeting Notes

What it does:
Automatically transcribes meetings and summarizes key points.

Best for: Work calls, lectures, interviews

Why it shines:

  • Accurate real-time transcription
  • Shareable summaries
  • Saves time re-listening to recordings

6. Trello + AI – Smarter Boards

What it does:
Trello’s AI helps automate task prioritization, generate ideas, and simplify planning.

Best for: Project tracking, personal to-dos

Why it shines:

  • Visual boards you can customize
  • AI suggestions keep you organized

7. Zapier AI – Automate Repetitive Tasks

What it does:
Connects apps and automates workflows (e.g., save attachments to cloud, send alerts, update spreadsheets).

Best for: Repetitive tasks, cross-app automation

Why it shines:

  • Works with 5,000+ apps
  • Saves hours on manual work

8. Jasper – AI for Content Creators

What it does:
Helps you write blog posts, ads, social media text, descriptions, and more.

Best for: Marketers, bloggers, creators

Why it shines:

  • Templates for different content types
  • Tone and style customization

9. AI Search Tools (Perplexity, You.com)

What they do:
Provide AI-enhanced search with concise answers, citations, and summaries.

Best for: Quick research and fact gathering

Why they shine:

  • Better than traditional search for quick comprehension
  • Saves time digging through multiple pages

10. AI Email Assistants (e.g., Superhuman AI)

What they do:
Generate replies, summarize threads, prioritize messages.

Best for: Busy professionals

Why they shine:

  • Faster inbox management
  • Smarter response suggestions

How to Pick the Right AI Tools

🔹 Start with your need: Writing? Planning? Meetings?
🔹 Don’t overload: Use a few tools deeply rather than many lightly
🔹 Test free versions first: Most offer free tiers
🔹 Combine tools: ChatGPT + Grammarly + Canva covers most daily tasks