Back to blog
NodeJS

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

May 10, 2026 2 min read

What Is Node.js?

Node.js allows JavaScript to run outside the browser.

It is commonly used for:

  • Backend development

  • APIs

  • Servers

  • CLI tools


Step 1: Install Node.js

Download Node.js from:

Node.js Official Website

Install the LTS version.


Step 2: Verify Installation

Open terminal and run:

node -v


Example Output

v22.1.0


Check npm Installation

npm -v


What Is npm?

npm = Node Package Manager

Used to install JavaScript packages.


Step 3: Understanding Node REPL

REPL means:

LetterMeaning
RRead
EEvaluate
PPrint
LLoop

It is an interactive Node.js console.


Start REPL

node


Example

> 2 + 3


Output

5


Another Example

> console.log("Hello")


Output

Hello


Exit REPL

.exit

or press:

Ctrl + C twice


Step 4: Create Your First JavaScript File

Create a file:

app.js


Add Code

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


Step 5: Run the Script

Open terminal in project folder.

Run:

node app.js


Output

Hello Node.js


Node Execution Flow

Diagram: flowchart LR

Script → Runtime → Output Flow

Diagram: sequenceDiagram

Step 6: Create Your First Node.js Server

Node.js includes a built-in HTTP module.


Hello World Server

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


Output

Server running on port 3000


Open Browser

Visit:

http://localhost:3000


Browser Result

Hello World


How the Server Works

PartPurpose
http.createServer()Creates server
reqIncoming request
resServer response
res.end()Sends response
listen()Starts server

Server Request Flow

Diagram: flowchart LR

Stopping the Server

Press:

Ctrl + C

inside terminal.


Common Beginner Mistakes

MistakeFix
node appUse node app.js
Wrong folderOpen terminal in correct directory
Port already usedChange port number

Practice Exercise

Create math.js

console.log(10 + 5);


Run File

node math.js


Create Another Server

const http = require("http");

http.createServer((req, res) => {
  res.end("My First Server");
}).listen(4000);

Visit:

http://localhost:4000


Key Takeaways

ConceptSummary
Node.jsRuns JS outside browser
REPLInteractive Node console
node file.jsExecutes JS file
HTTP ModuleCreates servers
localhostYour local machine

Final Notes

Your first Node.js application teaches the core workflow:

Write JavaScript
↓
Run with Node.js
↓
See output/server response

This foundation is important before learning:

  • Express.js

  • APIs

  • Databases

  • Authentication

  • Real-world backend systems


0 Comments

Sign in to join the conversation

No comments yet. Be the first to comment!