Setting Up Your First Node.js Application Step-by-Step
Every developer remembers their first console.log().
That one tiny line that makes you feel like:
“Yes. I am officially a programmer now.”
And when starting backend development, Node.js is usually where that journey begins.
But for beginners, the first setup can feel unnecessarily confusing.
People throw around terms like:
- runtime
- REPL
- server
- environment
- localhost
And suddenly:
you just wanted to print “Hello World” but now it feels like launching a satellite.
So in this article, we are going to build your first Node.js application from absolute scratch.
No frameworks.
No unnecessary complexity.
No “just trust me bro” explanations.
By the end, you will:
- install Node.js
- verify installation
- understand REPL
- create your first JavaScript file
- run it using Node
- build your first basic server
And most importantly:
you will actually understand what is happening.
First Understand: What Exactly Is Node.js?
Before installing anything, let’s clear the biggest confusion.
Node.js is not a programming language.
You still write:
- JavaScript
But normally JavaScript runs inside:
- browsers
Like:
- Chrome
- Firefox
- Edge
Node.js allows JavaScript to run:
- outside the browser
- directly on your computer/server
Meaning JavaScript can now:
- create servers
- work with files
- access databases
- build APIs
- handle backend logic
Basically:
Node.js gave JavaScript a job outside the browser.
Installing Node.js
To install Node.js, go to the official website:
You will usually see:
- LTS Version
- Current Version
Which One Should You Install?
Install:
LTS Version
LTS means:
Long Term Support
It is:
- stable
- tested
- safer for beginners and production apps
The “Current” version contains newer features but may not always be stable.
So unless you enjoy debugging mysterious problems at 2 AM:
use LTS.
Installation Process
The setup is mostly:
- Next
- Next
- Accept
- Install
- Finish
Classic software installation ritual.
Node.js installation also installs:
npm
npm stands for:
Node Package Manager
It helps install packages and libraries.
We will use it later.
Checking If Node.js Is Installed
After installation, open your terminal.
You can use:
- CMD
- PowerShell
- Terminal
- VS Code terminal
Now type:
```bash id="s7a2d1"
node -v
Example output:
```bash id="x8s2k1"
v22.3.0
This means:
- Node.js is successfully installed
Now check npm:
```bash id="m3s8d1"
npm -v
Example:
```bash id="j3k8f2"
10.8.1
Done.
Your machine is now officially ready for backend development.
Congratulations.
You now possess the power to accidentally break production servers in the future.
Understanding the Node REPL
Before creating files, we need to understand something called:
REPL
REPL stands for:
```text id="r1a8s3"
Read
Evaluate
Print
Loop
Sounds complicated.
It is actually very simple.
---
# What REPL Does
REPL is basically:
> a live JavaScript playground inside the terminal.
You type JavaScript.
Node.js executes it immediately.
---
# Start REPL
Open terminal and type:
```bash id="t9s7d1"
node
Now your terminal changes into interactive mode.
Example:
```bash id="k8s2p4"
Now try this:
```js id="q1p9x2"
2 + 2
Output:
```text id="w2s8m4"
4
Try another:
```js id="e9d2s1"
console.log("Hello Shivam")
Output:
```text id="y3f8c1"
Hello Shivam
This is REPL.
Why REPL Is Useful
REPL is great for:
- testing code quickly
- checking logic
- debugging small things
- learning JavaScript basics
Instead of creating files repeatedly.
Think of it like:
rough notebook work before final answer.
Exit REPL
To exit:
Press:
```text id="p0s9z1"
CTRL + C
twice.
Or type:
```js id="n8d3x7"
.exit
Creating Your First Node.js File
Now let’s create an actual JavaScript file.
Create a folder:
```text id="u7x2m9"
my-first-node-app
Inside it create a file:
```text id="z4m8k2"
app.js
Now write:
```js id="v8s1c2"
console.log("Hello from Node.js");
Save the file.
---
# Running Your First Node.js Script
Open terminal inside the project folder.
Run:
```bash id="l2p8x1"
node app.js
Output:
```text id="h8s2w4"
Hello from Node.js
And there it is.
Your first Node.js program.
Tiny line.
Massive moment.
---
# What Actually Happened Here?
When you ran:
```bash id="d8f2s9"
node app.js
Node.js:
- opened the file
- read JavaScript code
- executed it using the V8 engine
- displayed output in terminal
Simple Execution Flow
```text id="o8w2p1"
app.js
↓
Node.js Runtime
↓
V8 JavaScript Engine
↓
Execution
↓
Terminal Output
That is the basic flow of Node.js.
---
# Understanding the Node Runtime
A lot of beginners think Node.js is only:
> “something that runs JavaScript.”
But internally it is much bigger.
Node.js contains:
* V8 JavaScript Engine
* APIs
* Event Loop
* File System Access
* Networking Capabilities
This combination creates a backend runtime environment.
Without Node.js:
JavaScript alone cannot:
* read files
* create servers
* access operating system features
Browsers intentionally restrict that for security reasons.
---
# Writing Your First Hello World Server
Now comes the fun part.
We are going to create an actual server.
Still without frameworks.
No Express.
No shortcuts.
Pure Node.js.
---
# Create Server File
Inside `app.js` write:
```js id="q7s1m2"
const http = require("http");
const server = http.createServer((req, res) => {
res.write("Hello World");
res.end();
});
server.listen(3000, () => {
console.log("Server running on port 3000");
});
Now run:
```bash id="r9x2s1"
node app.js
Output:
```text id="j2m8d4"
Server running on port 3000
What Is Happening Here?
Let’s break this down slowly.
Step 1: Import HTTP Module
```js id="f7d1p9"
const http = require("http");
Node.js has built-in modules.
`http` helps create web servers.
---
## Step 2: Create Server
```js id="a8s2d7"
http.createServer()
This creates a server object.
Step 3: Handle Request and Response
```js id="m8s2p1"
(req, res)
* `req` = incoming request
* `res` = outgoing response
---
## Step 4: Send Response
```js id="c2d9w1"
res.write("Hello World");
Sends data to browser.
Step 5: End Response
```js id="b7f3x1"
res.end();
Ends the response cycle.
Without this:
browser keeps waiting forever.
Like waiting for a friend who said:
> “5 minutes away.”
---
## Step 6: Start Server
```js id="t2w8n1"
server.listen(3000)
Starts server on port 3000.
Testing the Server
Open browser and visit:
```text id="w9s2l1"
http://localhost:3000
You will see:
```text id="v7d1m8"
Hello World
You officially built your first backend server.
Not copied.
Actually understood.
Huge difference.
Understanding localhost
localhost means:
your own computer
Port 3000 is like:
a specific door of your application.
Different applications use different ports.
Examples:
- 3000
- 5000
- 8000
- 8080
Visual Flow of Server Request
```text id="p2x7s4"
Browser Request
↓
localhost:3000
↓
Node.js Server
↓
Handles Request
↓
Sends Response
↓
Browser Displays Output
This is the foundation of backend development.
Literally everything grows from here.
---
# Common Beginner Mistakes
## Forgetting to Save File
You change code.
Run program.
Nothing changes.
Because:
> file was never saved.
Classic beginner attack.
---
## Wrong File Name
Running:
```bash id="n7s2p1"
node index.js
when file is actually:
```text id="m8s1x4"
app.js
Result:
error.
---
## Port Already In Use
Sometimes port 3000 is occupied.
Error example:
```text id="k2d9p1"
EADDRINUSE
Just change port:
```js id="f8w2d1"
server.listen(5000)
---
# Why Learning Core Node.js Matters
A lot of beginners jump directly into:
* Express
* Next.js
* NestJS
Without understanding Node.js basics.
Then one small error appears and everything collapses emotionally.
Understanding:
* server creation
* request handling
* runtime behavior
* modules
makes frameworks easier later.
Because frameworks are just:
> abstractions built on top of Node.js.
---
# Quick Revision
## Node.js Is:
* a JavaScript runtime
* used outside browsers
* used for backend development
---
## REPL Means:
```text id="x8c1v7"
Read
Evaluate
Print
Loop
Interactive JavaScript environment.
Run Node File Using:
```bash id="l9p2s1"
node filename.js
---
## Create Basic Server Using:
```js id="u2s8m1"
http.createServer()
Access Server Using:
```text id="g7s1x9"
http://localhost:3000
---
# Final Thoughts
Your first Node.js application is not just about printing:
```js id="n2d8s4"
Hello World
It is about understanding:
- how JavaScript runs outside browsers
- how servers work
- how requests and responses behave
- how backend systems begin
Every advanced backend application:
- authentication systems
- APIs
- chat apps
- streaming platforms
- real-time systems
starts from these exact basics.
And honestly, backend development becomes far less scary once you realize:
A server is just code waiting for someone to say hello first.
Top comments (0)