Skip to main content

Command Palette

Search for a command to run...

Getting Started with Node.js

Updated
•2 min read•View as Markdown

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

Before building applications with Node.js, you first need to install it and run your first program.

In this article, we’ll create:

  • First Node.js script

  • First server

  • Understand Node REPL


Installing Node.js

Download Node.js from:

Node.js Official Website https://nodejs.org/

Install the LTS version because it is more stable for beginners.

After installation, Node.js and npm are automatically installed.


Checking Node.js Installation

Open terminal or command prompt and run:

node -v

If Node.js is installed correctly, it will show a version number.

Example:

v22.0.0

You can also check npm:

npm -v

Understanding Node REPL

REPL stands for:

Read

Eval

Print

Loop

It is an interactive Node.js environment where you can run JavaScript directly from the terminal.

Start REPL using:

node

Now you can write JavaScript:

2 + 2

Output:

4

Exit REPL using:

.exit

Creating Your First JavaScript File

Create a file named:

app.js

Add this code:

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

Running Script Using Node Command

Run the file using:

node app.js

Output:

Hello Node.js

Node.js Execution Flow

JavaScript File
        ↓
Node.js Runtime
        ↓
Code Executes
        ↓
Output Displays

Writing Hello World Server

Now let’s create a simple server.

Replace code inside app.js with:

const http = require("http");

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

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

Run server:

node app.js

Open browser and visit:

http://localhost:3000

You’ll see:

Hello World

How the Server Works

Browser Request
       ↓
Node.js Server Receives Request
       ↓
Response Sent Back
       ↓
Browser Displays Output

Final Thoughts

Getting started with Node.js is simple:

  • Install Node.js

  • Use REPL for quick testing

  • Create JS files

  • Run scripts using node

  • Build your first server

These basics are the foundation for learning backend development with Node.js.