Skip to main content

Command Palette

Search for a command to run...

Setting Up Your First Node.js Application Step-by-Step

Updated
Setting Up Your First Node.js Application Step-by-Step

So far in this series, you’ve understood how Node.js works internally.

You know about its single-threaded nature, non-blocking behavior, and the event loop.

Now it’s time to actually use it.

This is where things start becoming real.


Installing Node.js

To begin, you need Node.js installed on your system.

Go to the official website of Node.js and download the recommended version for your operating system.

The installation process is straightforward and works similarly across Windows, macOS, and Linux.

Once installed, Node.js gives you:

  • a runtime to execute JavaScript

  • a command-line tool (node)


Checking Installation

After installation, open your terminal or command prompt and run:

node -v

If everything is installed correctly, you will see a version number.

v18.x.x

You can also check npm (Node Package Manager):

npm -v

This confirms your environment is ready.


Understanding Node REPL

Before writing files, let’s understand something called REPL.

REPL stands for:

  • Read

  • Evaluate

  • Print

  • Loop

It is an interactive environment where you can write JavaScript and see the result instantly.

Start it by typing:

node

Now you can run code directly:

> console.log("Hello from REPL")
Hello from REPL

This is useful for quick testing and experimentation.

To exit:

.exit

Creating Your First JavaScript File

Now let’s move to actual coding.

Create a file called:

app.js

Inside it, write:

console.log("Hello from Node.js");

Running Your First Script

To run this file, go to the terminal and execute:

node app.js

Output:

Hello from Node.js

This is your first Node.js program running outside the browser.


Understanding What Just Happened

You wrote JavaScript in a file.

Node.js took that file, executed it using its runtime, and printed the result to the terminal.

You can visualize it like this:

app.js → Node.js runtime → Output in terminal

Writing Your First Server

Now let’s take a small step toward backend development.

Create a simple server.

const http = require("http");

const server = http.createServer((req, res) => {
  res.end("Hello World from Node.js Server");
});

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

Running the Server

Run the file again:

node app.js

You will see:

Server running on port 3000

Now open your browser and go to:

http://localhost:3000

You will see:

Hello World from Node.js Server

Understanding the Flow

Here’s what is happening behind the scenes:

Browser → Request → Node.js Server → Response → Browser

Your server is now handling requests.

This is your first backend application.


Why This Matters

This step might feel simple, but it is important.

You have:

  • installed a runtime

  • executed JavaScript outside the browser

  • created your first server

  • handled a real HTTP request

This is the foundation of everything that comes next.


Final Thought

Node.js is not just about writing code.

It is about running JavaScript in a completely different environment.

Once you understand how to set it up and execute code, you are ready to build real applications.

Express.Js Basics

Part 1 of 4

Express.js Basics is a beginner-friendly series designed to help you build backend APIs using Node.js and Express. You’ll learn how to create routes, handle requests and responses, use middleware, and structure your backend applications in a clean and scalable way. By the end, you’ll be able to build real-world APIs with confidence.

Up next

Creating Routes and Handling Requests with Express

In the previous blog, you created your first server using Node.js. You used the built-in http module and handled a request manually. It worked, but it was not very convenient. As your application grow