Node.js lets us run JavaScript outside the browser. In this guide, weβll install Node, learn the terminal, explore npm, build a real web server, understand event-driven programming, and serve static files β all before jumping into Express.js π₯
π§ Why Node.js feels magical
In the previous article, we mentioned that JavaScript was designed to run only in browsers. Then Node.js came along, and suddenly everyone was like, βHold onβ¦ JavaScript can run on servers too?!β
Until then, JavaScript meant:
- button clicks
- animations
- form validation
- frontend headaches π
But with Node.js, suddenly JavaScript could:
- read files
- create APIs
- talk to databases
- stream videos
- run backend servers
In this article, Iβll walk you through the exact beginner path I wish someone had shown me earlier.
By the end, youβll:
β
Install Node.js
β
Understand the terminal without fear
β
Learn npm properly
β
Build your own Node server
β
Understand routing
β
Serve HTML/CSS files
β
Be fully ready for Express.js
π Prerequisites
You only need:
- Basic JavaScript knowledge
- A laptop π
- Node.js v20+ recommended
- β Coffee (strongly recommended)
π What Exactly is Node.js?
Node.js is a JavaScript runtime built on Chromeβs V8 engine.
That means:
It allows JavaScript to run outside the browser.
Instead of running only inside Chrome or Firefox, JavaScript can now run directly on your computer or server.
π Browser JavaScript vs Node.js
π» Getting Node.js
π’ Step 1: Download Node
Visit:
Download the LTS version.
π‘ Production note: Always prefer the LTS (Long Term Support) version for stability.
π’ Step 2: Verify Installation
Open terminal and run:
node -v
Example output:
v20.11.0
Now check npm:
npm -v
Example:
10.2.4
Boom π₯ Node installed successfully.
π₯οΈ Using the Terminal
We all were scared of it initially π
Most beginners avoid the terminal initially.
I did too.
Huge mistake.
The terminal is basically your direct communication line with the operating system.
Think of it like this:
| GUI | Terminal |
|---|---|
| Clicking buttons | Typing commands |
| Slower | Faster |
| Beginner friendly | Developer powerful |
π Essential Terminal Commands
Windows
Use:
- PowerShell
- Windows Terminal
macOS/Linux
Use:
- Terminal app
π Most Useful Commands
# Show current folder
pwd
# List files
ls
# Change folder
cd folder-name
# Create folder
mkdir my-project
# Create file
touch app.js
π Terminal Workflow
π οΈ Editors (VS Code or Claude)
You technically can write Node code in Notepad.
But please donβt torture yourself π.
π¦ VS Code (Recommended)
Why developers love it:
- Fast
- Free
- Great extensions
- Git integration
- Built-in terminal
- Excellent Node support
π Extensions I Recommend
| Extension | Why |
|---|---|
| ESLint | Catch JavaScript mistakes |
| Prettier | Auto formatting |
| Thunder Client | API testing |
| GitLens | Git superpowers |
π€ Claude Editor
Many developers also use:
Especially for:
- debugging help
- refactoring
- documentation generation
- learning concepts faster
- vibe coding (We'll discuss this in detail in future articles)
But honestly?
VS Code + Node is still the gold standard for most beginners.
π¦ Understanding npm
npm stands for:
Node Package Manager
This is where Node becomes insanely powerful.
npm lets you install reusable packages instead of reinventing the wheel every time.
π§± Create Your First Project
mkdir node-demo
cd node-demo
Initialize project:
npm init -y
This creates:
package.json
π What is package.json?
Think of it like:
The Aadhaar card or identity card of your project π
It contains:
- project name
- dependencies
- scripts
- version
- metadata
π Example package.json
{
"name": "node-demo",
"version": "1.0.0",
"main": "app.js"
}
π How npm Works
π A Simple Web Server with Node.js
Now the fun part begins π₯
π Hello World Server
Create:
app.js
β Minimal Node Server
// Node.js v20
// Import Node's built-in HTTP module
const http = require('http');
// Create server
const server = http.createServer((request, response) => {
// Send HTTP status code
response.writeHead(200, {
'Content-Type': 'text/plain'
});
// Send response body
response.end('Hello World from Node.js π');
});
// Start listening on port 3000
server.listen(3000, () => {
// Callback runs once server starts
console.log('Server running at http://localhost:3000');
});
βΆοΈ Run the Server
node app.js
Visit:
http://localhost:3000
And there it is π
Your first Node web server.
β‘ Understanding Event-Driven Programming
This is THE core Node concept.
And honestly?
This is where many folks get confused initially.
π§ Traditional Programming
Traditional systems often wait for one task to finish before moving to the next.
Like standing in a railway booking queue π.
One person at a time.
π Nodeβs Event-Driven Model
Node works differently.
Instead of blocking everything:
- it listens for events
- processes callbacks
- handles async tasks efficiently
π Event Loop Explained
π Simple Event Example
// Node.js Events Module
const EventEmitter = require('events');
// Create event emitter instance
const emitter = new EventEmitter();
// Listen for custom event
emitter.on('orderPlaced', () => {
console.log('π Pizza order received');
});
// Emit event
emitter.emit('orderPlaced');
Output:
π Pizza order received
π§ Routing in Node.js
Routing means:
Sending different responses for different URLs.
Example:
| URL | Response |
|---|---|
/ |
Home page |
/about |
About page |
/contact |
Contact page |
β Basic Routing Example
// app.js
const http = require('http');
const server = http.createServer((req, res) => {
// Homepage route
if (req.url === '/') {
res.writeHead(200, {
'Content-Type': 'text/plain'
});
res.end('π Welcome Home');
}
// About page route
else if (req.url === '/about') {
res.writeHead(200, {
'Content-Type': 'text/plain'
});
res.end('βΉοΈ About Us');
}
// Fallback route
else {
res.writeHead(404, {
'Content-Type': 'text/plain'
});
res.end('β Page Not Found');
}
});
// Start server
server.listen(3000, () => {
console.log('Server started');
});
π How Routing Works
π Serving Static Resources
Static resources include:
- HTML
- CSS
- JavaScript
- Images
Without this, websites would look like 1998 π .
π Project Structure
project/
β
βββ app.js
βββ public/
β βββ index.html
β βββ style.css
β Serve HTML File
// Node.js v20
const http = require('http');
const fs = require('fs');
const server = http.createServer((req, res) => {
// Read HTML file
fs.readFile('./public/index.html', (error, data) => {
// Handle file read errors
if (error) {
res.writeHead(500);
res.end('Internal Server Error');
return;
}
// Send HTML response
res.writeHead(200, {
'Content-Type': 'text/html'
});
res.end(data);
});
});
server.listen(3000);
π Example HTML
<!DOCTYPE html>
<html>
<head>
<title>Node Demo</title>
</head>
<body>
<h1>π Node.js Server</h1>
</body>
</html>
π¨ Serve CSS File
// Simplified CSS serving example
if (req.url === '/style.css') {
fs.readFile('./public/style.css', (err, data) => {
res.writeHead(200, {
'Content-Type': 'text/css'
});
res.end(data);
});
}
π€― What Broke When I Tried This
TBH, many things π
β Mistake 1: Wrong File Path
ENOENT: no such file or directory
β Fix
Always verify folder structure carefully.
β Mistake 2: Port Already in Use
EADDRINUSE
β Fix
Another app is using the same port.
Simply, change the port number. (3000 to something else which is not getting used π)
β Mistake 3: Browser Keeps Loading Forever
Usually happens because:
res.end()
was forgotten.
π Why Express.js Was Needed
After writing enough raw Node servers, developers realized:
βDudeβ¦ this is becoming repetitive.β
Things became messy quickly:
- manual routing
- manual headers
- repetitive file handling
- middleware chaos
Thatβs exactly why Express.js became popular.
π Raw Node vs Express
Express dramatically reduced boilerplate code.
β Caffeine Scale
| Topic | Complexity |
|---|---|
| Installing Node | β |
| npm basics | ββ |
| Routing | ββ |
| Event loop | ββββ |
π― Onward to Express.js
Now you understand:
β
Node installation
β
Terminal basics
β
npm
β
HTTP servers
β
Event-driven programming
β
Routing
β
Static files
Youβre officially ready for:
π Express.js
But donβt worry β if you missed anything, weβll come back to some of these topics individually and go way deeper π
And trust meβ¦
Once you use Express routing after raw Node routing, it feels like upgrading from manual gear driving to automatic π
π Key Takeaways
- Node.js lets JavaScript run outside browsers
- npm powers the massive Node ecosystem
- Node uses event-driven architecture
- You can build web servers with built-in modules
- Routing and static file serving are fundamental backend concepts
- Express simplifies all of this beautifully
π’ Whatβs Next?
In the next article weβll cover:
- Scaffolding
- Installing Express
- Request/response lifecycle
- Middleware
π¬ Your Turn
What confused you most when learning Node?
- npm?
- terminal?
- async programming?
- routing?
And did you also use incorrect file path at least once? π
π£ Call To Action
If this article helped you:
- β Bookmark it
- π Share with a beginner developer
- π Build your own tiny Node server today
- π¨βπ» Follow for more backend deep dives






Top comments (0)