Setting Up Your First Node.js Application Step-by-Step
A beginner-friendly guide to installing Node.js, understanding the Node runtime, using the REPL, and creating your first server without any frameworks.

Introduction
If you want to start backend development with JavaScript, the first thing you need is Node.js.
Node.js allows JavaScript to run outside the browser. Instead of executing code in Chrome or Firefox, Node.js executes JavaScript directly on your computer or server.
That means you can:
Build backend APIs
Create web servers
Work with files
Build CLI tools
Automate tasks
Create full-stack applications
In this article, you’ll learn how to:
Install Node.js
Verify installation
Understand the Node REPL
Create your first JavaScript file
Run Node scripts
Build a simple Hello World server
By the end, you’ll have your first Node.js application running successfully.
What is Node.js?
Node.js is a JavaScript runtime environment built on Chrome’s V8 JavaScript engine.
Normally, JavaScript runs inside browsers.
Node.js makes it possible to run JavaScript on your operating system directly.
How Node.js Executes Code
Here’s the basic execution flow:
JavaScript File
│
▼
Node.js Runtime
│
▼
V8 Engine Compiles Code
│
▼
Execution Happens
│
▼
Output Appears in Terminal
Installing Node.js
To install Node.js:
Visit the official website:
Download the LTS (Long Term Support) version.
The LTS version is recommended for beginners because it is:
Stable
Well-tested
Widely supported
Installation Steps (OS-Neutral)
The installation process is mostly similar across operating systems:
Step 1: Download Installer
Download the installer for your operating system.
Step 2: Run Installer
Open the downloaded installer and continue with default settings.
Step 3: Finish Installation
Once completed, Node.js and npm will both be installed automatically.
What is npm?
npm stands for:
Node Package Manager
It helps you install libraries and tools for Node.js projects.
When Node.js installs, npm comes included automatically.
Checking Node.js Installation
After installation, open your terminal or command prompt.
Run:
node -v
You should see something like:
v22.3.0
Now check npm:
npm -v
Example output:
10.8.1
If both commands work, Node.js is installed correctly.
Understanding the Node REPL
Before creating files, it’s important to understand the Node REPL.
REPL stands for:
Read → Evaluate → Print → Loop
It is an interactive environment where Node.js executes JavaScript line by line.
Starting the REPL
Open terminal and type:
node
You’ll see something like:
>
Now you can write JavaScript directly.
Example:
2 + 3
Output:
5
Another example:
const name = "Subransu"
console.log(name)
Output:
Subransu
How REPL Works Internally
You Type Code
│
▼
Node Reads Input
│
▼
Code Gets Evaluated
│
▼
Result Gets Printed
│
▼
REPL Waits Again
That repeating cycle is why it’s called REPL.
Exiting the REPL
To exit:
.exit
Or press:
Ctrl + C (twice)
Creating Your First JavaScript File
Now let’s create an actual Node.js program.
Create a folder anywhere on your computer:
my-first-node-app
Inside it, create a file:
app.js
Writing Your First Program
Open app.js and add:
console.log("Hello World")
Save the file.
Running a Node.js Script
Open terminal inside the project folder.
Run:
node app.js
Output:
Hello World
Congratulations 🎉
You just executed your first Node.js application.
Understanding What Happened
Let’s break the process down:
app.js
│
▼
node app.js
│
▼
Node Runtime Starts
│
▼
JavaScript Executes
│
▼
console.log() Prints Output
Creating Your First HTTP Server
Now let’s build a simple web server using only Node.js core modules.
Replace the content of app.js with:
const http = require("http")
const server = http.createServer((req, res) => {
res.write("Hello from Node.js Server")
res.end()
})
server.listen(3000, () => {
console.log("Server running on port 3000")
})
Understanding the Code
Importing HTTP Module
const http = require("http")
Node.js provides built-in modules.
The http module helps create web servers.
Creating the Server
http.createServer()
This creates an HTTP server.
The callback runs whenever a request reaches the server.
Request and Response Objects
(req, res)
reqcontains request informationressends response back to client
Sending Response
res.write("Hello from Node.js Server")
This sends text to the browser.
Ending Response
res.end()
This completes the response cycle.
Without this, the browser keeps waiting.
Starting the Server
server.listen(3000)
This starts the server on port 3000.
Running the Server
Run:
node app.js
Output:
Server running on port 3000
Now open your browser and visit:
http://localhost:3000
You’ll see:
Hello from Node.js Server
Server Request Flow Diagram
Browser Request
│
▼
localhost:3000
│
▼
Node.js Server Receives Request
│
▼
Callback Function Executes
│
▼
Response Sent Back
│
▼
Browser Displays Output
Difference Between Browser JavaScript and Node.js
| Browser JavaScript | Node.js |
|---|---|
| Runs inside browser | Runs on operating system |
| Uses DOM APIs | Uses system APIs |
| Cannot access filesystem directly | Can access files and OS |
| Mainly frontend | Mainly backend |
Common Beginner Mistakes
1. Node Command Not Found
This usually means:
Node.js is not installed
Terminal restarted incorrectly
PATH variable missing
Reinstall Node.js if needed.
2. Wrong File Name
Running:
node app.js
requires the file to actually exist.
Check spelling carefully.
3. Port Already in Use
If port 3000 is busy:
server.listen(5000)
Use another port.
Why Learning Core Node.js Matters
Many beginners jump directly into frameworks like Express.
But understanding core Node.js helps you learn:
How servers work
Request-response cycle
Runtime behavior
Backend fundamentals
Event-driven architecture
Frameworks become much easier afterward.
Final Project Structure
my-first-node-app/
│
├── app.js
Simple, clean, and enough to start learning Node.js.
Final Thoughts
Your first Node.js application is more than just “Hello World.”
You learned:
How Node.js works
How JavaScript runs outside browsers
What REPL means
How to execute scripts
How to create a basic HTTP server
These fundamentals form the base of backend development with JavaScript.
Once you understand these concepts clearly, moving into Express.js, APIs, databases, and full-stack development becomes much easier.
Happy coding 🚀




