A Beginner's Guide to Setting Up Node.js and Building Your First API
Jul 31,2026

If you've been working with JavaScript on the frontend, you've probably heard developers say:

"You should learn Node.js."

But what exactly is Node.js?

Is it a programming language?

Is it a framework?

Or is it something else?

If you're new to backend development, these questions are completely normal.

In this article, we'll understand what Node.js is, why it's one of the most popular backend technologies, how to install it on both Windows and macOS, and finally build your very first REST API.

Let's dive in!


What is Node.js?

Node.js is an open-source, cross-platform JavaScript runtime environment that allows you to run JavaScript outside of a web browser.

Before Node.js, JavaScript could only run inside browsers like Chrome, Firefox, or Edge. Developers mainly used JavaScript for frontend tasks such as:

  • Creating interactive user interfaces
  • Validating forms
  • Handling browser events
  • Manipulating HTML and CSS

Node.js changed everything.

It enables JavaScript to run on servers, allowing developers to build complete backend applications using the same language they use for frontend development.

Today, Node.js is widely used to build:

  • REST APIs
  • Backend services
  • Real-time chat applications
  • Streaming platforms
  • CLI (Command Line Interface) tools
  • Automation scripts
  • Microservices
  • IoT applications

In simple words,

Node.js allows JavaScript to become a full-stack programming language.


Is Node.js a Programming Language?

This is one of the most common misconceptions among beginners.

The answer is No.

  • JavaScript is the programming language.
  • Node.js is the runtime environment that executes JavaScript outside the browser.
  • Express.js is a framework built on top of Node.js that simplifies backend development.

Think of it like this:

JavaScript → Programming Language

Node.js → Runtime Environment

Express.js → Backend Framework

Why Do We Need Node.js?

Imagine you're building an e-commerce website.

The frontend displays products and provides a great user interface.

But where does the product data come from?

Who stores user accounts?

Who processes payments?

Who authenticates users?

Who communicates with the database?

That's where the backend comes in.

Node.js allows you to build that backend using JavaScript.

Instead of learning separate languages like Java, PHP, C#, or Python, developers can use JavaScript across the entire application—from frontend to backend.

This makes development faster, simpler, and easier to maintain.


Why is Node.js So Popular?

Node.js has become one of the most widely used backend technologies for several reasons.

1. JavaScript Everywhere

One language for the entire application.

Instead of switching between JavaScript on the frontend and another language on the backend, you can write everything using JavaScript.

This reduces context switching and improves productivity.

2. High Performance

Node.js is powered by Google's V8 JavaScript Engine, the same engine used in Chrome.

The V8 engine compiles JavaScript directly into machine code, making execution extremely fast.

This is one of the reasons Node.js applications perform well.

3. Non-Blocking and Asynchronous

One of Node.js's biggest strengths is its non-blocking I/O model.

Traditional servers process requests one after another.

Request 1
↓

Wait...

↓

Request 2
↓

Wait...

↓

Request 3

Node.js processes requests asynchronously.

Request 1 ─┐
Request 2 ─┼── Processing Together
Request 3 ─┘

Instead of waiting for one request to complete before processing the next, Node.js can handle many requests simultaneously.

This makes it ideal for applications that serve thousands of users at the same time.

4. Huge Package Ecosystem (npm)

Node.js includes npm (Node Package Manager).

npm contains millions of open-source packages that save developers countless hours.

Need authentication?

Install a package.

Need image processing?

Install a package.

Need email functionality?

Install a package.

Need JWT authentication?

There's a package for that too.

Instead of reinventing the wheel, developers can leverage the open-source ecosystem.

5. Large Community Support

Node.js has one of the largest developer communities.

If you encounter an issue, chances are someone has already solved it.

You'll find:

  • Documentation
  • Tutorials
  • YouTube videos
  • GitHub repositories
  • Stack Overflow discussions

This makes learning and troubleshooting much easier.


When Should You Use Node.js?

Node.js is an excellent choice for:

  • REST APIs
  • Real-time chat applications
  • Social media platforms
  • Video streaming services
  • Dashboards
  • Backend for mobile applications
  • Microservices
  • Server-side rendered applications
  • Single Page Application (SPA) backends

However, if your application performs heavy CPU-intensive tasks like video rendering or scientific calculations, you may want to use worker threads or dedicated services for those workloads.


Installing Node.js

Installing Node.js is straightforward on both Windows and macOS.


Install Node.js on Windows

Step 1: Download Node.js

Visit the official Node.js website:

https://nodejs.org

Download the LTS (Long-Term Support) version.

The LTS version is recommended because it is stable and suitable for most production applications.

Step 2: Run the Installer

Open the downloaded installer.

Keep the default settings and click:

Next

↓

Next

↓

Install

↓

Finish

The installer will automatically install:

  • Node.js
  • npm (Node Package Manager)

Step 3: Verify the Installation

Open Command Prompt or PowerShell and run:

node -v

Example output:

v24.5.0

Now verify npm:

npm -v

Example output:

11.5.0

If both commands return version numbers, the installation was successful.


Install Node.js on macOS

There are two popular methods.

Option 1: Official Installer

Visit:

https://nodejs.org

Download the macOS installer and complete the installation.

Option 2: Install Using Homebrew

If you already have Homebrew installed:

brew install node

Verify the installation:

node -v

npm -v

What is npm?

npm stands for Node Package Manager.

It comes bundled with Node.js.

npm helps developers:

  • Install packages
  • Remove packages
  • Update packages
  • Manage project dependencies
  • Run project scripts

For example, to install Express:

npm install express

Create Your First Node.js Project

Let's build our first backend application.

Create a project folder.

mkdir first-node-api

Navigate into the project.

cd first-node-api

Initialize the project.

npm init -y

This command creates a package.json file.

The package.json file stores important information about your project, including:

  • Project name
  • Version
  • Dependencies
  • Scripts
  • License

Install Express.js

Express is the most popular framework for building APIs using Node.js.

Install it using npm.

npm install express

After installation, you'll notice a new folder called node_modules.

This folder contains all the installed packages required by your project.


Create Your First API

Create a new file called:

index.js

Add the following code:

const express = require("express");

const app = express();

const PORT = 3000;

app.get("/", (req, res) => {
  res.send("Hello from Node.js API 🚀");
});

app.listen(PORT, () => {
  console.log(`Server is running on http://localhost:${PORT}`);
});

Understanding the Code

Let's understand what each part does.

Import Express

const express = require("express");

This imports the Express library into your application.

Create an Express Application

const app = express();

This creates an Express application instance.

Create a Route

app.get("/", (req, res) => {
  res.send("Hello from Node.js API 🚀");
});

This defines a GET endpoint.

Whenever someone visits the root URL (/), the server responds with:

Hello from Node.js API 🚀

Start the Server

app.listen(PORT, () => {
  console.log(`Server is running on http://localhost:${PORT}`);
});

This starts the server on port 3000.


Run the Application

Start the server by running:

node index.js

You'll see:

Server is running on http://localhost:3000

Open your browser and visit:

http://localhost:3000

You should see:

Hello from Node.js API 🚀

Congratulations! 🎉

You've successfully built your first Node.js API.


Create Another API Endpoint

Let's return some JSON data.

Add the following code below the first route:

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

Restart the server and open:

http://localhost:3000/users

You'll receive:

[
  {
    "id": 1,
    "name": "John"
  },
  {
    "id": 2,
    "name": "Emma"
  }
]

This is how APIs typically send structured data to frontend applications.


Project Structure

Your project should now look like this:

first-node-api/
│
├── node_modules/
├── package.json
├── package-lock.json
└── index.js

Common Beginner Mistakes

If you're just starting with Node.js, avoid these common mistakes:

  • Forgetting to install Express before running the application.
  • Running the server from the wrong directory.
  • Using a port that's already occupied.
  • Forgetting to restart the server after making changes.
  • Typing the wrong URL while testing the API.

What's Next?

Now that you've built your first API, continue learning these topics:

  • Understanding HTTP Methods (GET, POST, PUT, PATCH, DELETE)
  • Express Routing
  • Middleware
  • Request and Response Objects
  • Error Handling
  • Environment Variables (.env)
  • Working with MongoDB
  • Authentication using JWT
  • REST API Best Practices
  • MVC Architecture
  • Building CRUD APIs

These topics will help you build real-world backend applications.


Final Thoughts

Node.js has transformed JavaScript into a powerful backend technology, enabling developers to build complete web applications using a single programming language.

Its speed, asynchronous architecture, and vast npm ecosystem make it one of the most popular choices for backend development today.

In this article, you learned:

  • What Node.js is
  • Why it's widely used
  • How to install it on Windows and macOS
  • What npm is and why it's important
  • How to create your first Node.js project
  • How to build and run your first REST API using Express

This is just the beginning of your backend journey. As you continue learning, you'll explore databases, authentication, middleware, file uploads, and many other concepts that will help you build production-ready applications.

Happy Coding! 🚀