What is Node.js? JavaScript on the Server Explained
What Is Node.js?
Node.js is a JavaScript runtime that allows JavaScript to run outside the browser.
Before Node.js:
JavaScript mainly worked inside browsers
After Node.js:
JavaScript could also run on servers
What Is a Runtime?
JavaScript is a programming language.
A runtime is the environment where the language executes.
Example
Why JavaScript Was Originally Browser-Only
JavaScript was created for browsers to make web pages interactive.
Examples:
Button clicks
Form validation
Animations
Dynamic content
Browsers provided the environment for JavaScript execution.
Browser JavaScript Example
document.querySelector("button");
This works only in browsers because:
Browsers provide DOM APIs
The Problem Before Node.js
Developers often used:
JavaScript for frontend
PHP/Java/Python for backend
This meant learning multiple languages.
How Node.js Changed Everything
Node.js introduced JavaScript execution on servers.
Now developers could use:
JavaScript for both frontend and backend
Browser JS vs Node.js
Browser JavaScript vs Server JavaScript
Example Node.js Code
console.log("Hello from Node.js");
Run using:
node app.js
What Makes Node.js Possible?
Node.js uses:
Google Chrome's V8 Engine
What Is the V8 Engine?
V8 is the JavaScript engine created by Google for Chrome.
It converts JavaScript into machine code so computers can execute it quickly.
High-Level Node.js Architecture
Node.js Adds Extra Features
Browsers provide:
DOM
Window object
Node.js provides:
File system access
HTTP server support
Networking
Process handling
Example File System Access
const fs = require("fs");
fs.writeFileSync(
"hello.txt",
"Hello Node.js"
);
Browsers cannot normally do this.
Event-Driven Architecture
Node.js is event-driven.
Meaning:
It reacts to events asynchronously
Examples:
HTTP requests
File reads
Database responses
Event-Driven Flow
Why Developers Adopted Node.js
Node.js became popular because it offered:
Comparing Node.js With Traditional Backends
Traditional Blocking Example
Request arrives ↓ Server waits for DB ↓ Next request waits
Node.js Style
Request arrives ↓ Start async task ↓ Handle other requests meanwhile
Why This Matters
Node.js handles many simultaneous users efficiently.
Especially useful for:
APIs
Chat apps
Streaming
Real-time apps
Real-World Use Cases
Node.js is commonly used for:
Real-World Companies Using Node.js
Many companies use Node.js including Netflix, Uber, PayPal, LinkedIn, and Walmart.
Simple Node.js HTTP Server
const http = require("http");
const server = http.createServer(
(req, res) => {
res.end("Hello World");
}
);
server.listen(3000);
Node.js Runtime Overview
Common Beginner Misunderstanding
Incorrect:
Node.js is a programming language
Correct:
Node.js is a JavaScript runtime
Important Point
JavaScript = Language Node.js = Runtime Environment
Key Takeaways
Final Notes
Node.js changed web development significantly because developers could finally build:
Frontend
Backend
APIs
Realtime systems
using a single language: JavaScript.
Its event-driven architecture and non-blocking model made it especially powerful for modern scalable web applications.
0 Comments
Sign in to join the conversation
No comments yet. Be the first to comment!