โ† Back to list

๐Ÿš€ Beginner Guide: How to Build a Simple Node.js API

Building your first API might feel confusing at first โ€” but itโ€™s actually simpler than it looks. In this guide, Iโ€™ll show you how to createโ€ฆ

Sushma R Gowda ยท 2026-04-24 06:49 ยท 1 claps ยท 1.6 min read
#nodejs-development #backend-development #javascript #web-development #beginner
Open on Medium โ†—
Wiki topics: ๐ŸŒ ยท Web Development

๐Ÿš€ Beginner Guide: How to Build a Simple Node.js API

Building your first API might feel confusing at first โ€” but itโ€™s actually simpler than it looks. In this guide, Iโ€™ll show you how to create a basic API using Node.js step by step.

๐Ÿง  What is an API?

An API (Application Programming Interface) allows different applications to communicate with each other.

For example:

  • Your frontend (React app)
  • Talks to your backend (Node.js API)

โš™๏ธ Step 1: Setup Your Project

First, create a new folder and initialize a project:

mkdir simple-api
cd simple-api
npm init -y

๐Ÿ“ฆ Step 2: Install Required Packages

Weโ€™ll use Express to simplify API creation:

npm install express

๐Ÿ“ Step 3: Create Server File

Create a file called 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}`);
});

๐Ÿ”— Step 4: Create Your First API Route

Add a simple GET endpoint in index.js:

app.get("/", (req, res) => {
  res.send("Hello, API is working!");
});

โ–ถ๏ธ Run Your Server

Start your server using:

node index.js

Then open your browser: ๐Ÿ‘‰ http://localhost:3000

You should see:

Hello, API is working!

๋ฉ”ํƒ€๋ฐ์ดํ„ฐ
post_id
09cbf4fa9d2a
slug
beginner-guide-how-to-build-a-simple-node-js-api-09cbf4fa9d2a
url
https://medium.com/@sushmargowda27/beginner-guide-how-to-build-a-simple-node-js-api-09cbf4fa9d2a
canonical_url
https://medium.com/@sushmargowda27/beginner-guide-how-to-build-a-simple-node-js-api-09cbf4fa9d2a
author_url
https://medium.com/@sushmargowda27
status
ok
fetched_at
2026-06-09 15:37:30