Skip to main content

Command Palette

Search for a command to run...

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

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

If you want to start backend development with JavaScript, Node.js is one of the best places to begin. It allows you to run JavaScript outside the browser and build servers, APIs, tools, and more.

In this guide, you'll learn how to install Node.js, verify the setup, use the Node REPL, create your first JavaScript file, and run a simple Hello World server.

What is Node.js?

Node.js is a JavaScript runtime built on Chrome’s V8 engine. It allows developers to run JavaScript on their computer or server instead of only inside a browser.

That means you can use JavaScript for:

Backend development APIs Real-time apps Command-line tools Automation scripts

Installing Node.js

Visit the official Node.js website and download the LTS (Long Term Support) version:

https://nodejs.org

The LTS version is recommended because it is stable and widely used in production.

Installation Steps (All Operating Systems)

Windows

  1. Download installer (.msi)

  2. Run setup wizard

  3. Click Next until installation completes

macOS

  1. Download installer (.pkg)

2. Run installer and finish setup

Linux

Use your package manager or install from Node.js official site.


Check Installation in Terminal

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

node -v

Example output:

v22.5.1

Now check npm (Node Package Manager):

npm -v

Example:

10.8.2

If both commands work, Node.js is installed correctly.


Understanding Node REPL

REPL stands for:

  • Read

  • Evaluate

  • Print

  • Loop

It is an interactive environment where you can write JavaScript directly in terminal.

Start REPL:

node

You’ll see:

>

Now type:

2 + 3

Output:

5

Try variables:

let name = "Ritu"
name

To exit REPL:

.exit

or press:

Ctrl + C (twice)

Create Your First JavaScript File

Create a file named:

app.js

Add this code:

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

Save the file.


Run Script Using Node Command

Open terminal in the same folder and run:

node app.js

Output:

Hello from Node.js

This means Node.js executed your JavaScript file successfully.


6. Write Your First Hello World Server

Now let’s create a basic web server.

Update app.js:

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");
});

Run:

node app.js

Output:

Server running on port 3000

Now open browser:

http://localhost:3000

You’ll see:

Hello World from Node.js Server

Node Execution Flow

app.js file
   ↓
node app.js
   ↓
Node Runtime Executes Code
   ↓
Output in Terminal / Browser

Server Request Flow

Browser Request
      ↓
localhost:3000
      ↓
Node.js Server
      ↓
Response Sent

Why This First Blog Matters

By doing this, you learned:

  • How to install Node.js

  • How to verify setup

  • How Node REPL works

  • How to run JavaScript outside browser

  • How to create a basic HTTP server

These are the foundations of backend development using Node.js.