← Back to Home
Article Detail
Creating API Using Express Js
Back End

Creating API Using Express Js

In this article, I want to share a simple way to start building an API using Express JS. The goal is not to make everything complicated, but to help beginners understand how an API works, how to create a server, and how to organize the code so it stays clean.

8 min readMarch 2026 ⭐ 4.6

When we learn backend development, one of the first things we usually meet is API development. At first it may look confusing, especially if we are still trying to understand the difference between frontend and backend. But actually, the basic idea is not too hard. An API is simply a bridge that helps applications talk to each other.

For example, imagine you have a frontend website that needs product data. The frontend will send a request to the backend, then the backend will process it and send back a response. That response is often in JSON format. This is why APIs are very important in modern applications.

One of the easiest tools to start learning API development in Node.js is Express JS. Express is lightweight, simple, and flexible. It does not force too many rules, so it is perfect for beginners who want to understand the flow first before moving into more complex architecture.

1. Create a New Node.js Project

The first step is creating a new Node.js project. This project folder will contain everything for our API, such as package information, server files, routes, and other backend logic.

mkdir express-api
cd express-api
npm init -y

After running those commands, Node.js will create a package.json file for your project. This file stores the basic information about your application and the packages you install later.

2. Install Express

Once the project is ready, the next step is installing Express. This package will help us create the server and define API routes more easily.

npm install express

Now Express is added to your project, and you are ready to create your first server.

3. Create the First Express Server

Create a file named app.js. This file will be the main entry point of your backend server. Inside this file, we can import Express, create an app, and run the server.

const express = require("express")

const app = express()

app.get("/", (req, res) => {
  res.json({
    message: "API is running"
  })
})

app.listen(3000, () => {
  console.log("Server running on port 3000")
})

In the code above, app.get("/") means we are creating a route for the root URL. When someone opens that URL, the server responds with JSON. This is already a very basic API response.

To run the server, use Node in your terminal.

node app.js

If everything works, your terminal will show that the server is running on port 3000.

4. Create Your First API Endpoint

Now let’s make the example a little more realistic. Instead of only returning a message, we can create an endpoint that returns a list of users.

app.get("/users", (req, res) => {
  const users = [
    { id: 1, name: "Riyanti" },
    { id: 2, name: "Alex" }
  ]

  res.json(users)
})

This route will return an array of users in JSON format. If you open /users in the browser or test it with Postman, you will see the response data directly.

This is where many beginners start understanding the role of backend. The frontend does not need to know how the data is stored. It only needs to request the data from the API.

5. Why Structure Matters

At the beginning, putting all the code in one file is okay. But as soon as your project starts growing, that approach quickly becomes messy. That is why it is a good habit to separate your project into folders with clear responsibilities.

For example, routes can handle endpoint definitions, controllers can handle request and response logic, and services can contain the main business logic. This makes the code easier to read and much easier to maintain.

project-api
│
├── controllers
│   └── userController.js
│
├── routes
│   └── userRoutes.js
│
├── services
│   └── userService.js
│
├── app.js
└── package.json

With this structure, your project becomes more scalable. When the application gets bigger, you will not feel lost because every file already has its own role.

6. Final Thoughts

Learning Express JS is a great starting point for backend development. You do not need to build something complex immediately. Start with a simple server, make one endpoint, understand the request and response flow, then slowly improve the project structure.

The most important thing is not how fancy the backend looks at the beginning. The most important thing is understanding the flow clearly: how a request comes in, how the backend processes it, and how the response is sent back.

Key Takeaway

If you are just starting backend development, Express JS is one of the easiest and most practical tools to learn. Start small, keep the structure clean, and focus on understanding how data moves between the client and the server.