What Exactly is Node.js?
hi its me
so today's topic is about nodejs yes what is node js why is nodejs who is nodejs and how is node js
everything about node js
just kidding π
we are just going to talk about node js like what is it really?
is it JavaScript?
is it a language?
like exactly what it is
so let begin i think i have talked shit for too long let start
First, What is Node.js?
Node.js is a JavaScript runtime that allows JavaScript to run outside the browser β most commonly on servers, backend systems, and command-line tools.
yes this is one of the best ways to explain node js (self appreciation moment waah wahi π)
Important things to know:
- Node.js is NOT a programming language
- Node.js is NOT a framework
- JavaScript is the programming language
Node.js is the environment/runtime that executes JavaScript on the server.
Originally JavaScript Was Only For Browsers
Originally, JavaScript was created to make websites interactive.
For example, browsers provide:
- JavaScript engine
- Browser APIs
- DOM access
Example:
document.getElementById("btn");
All these things only work because browsers provide:
documentwindow- DOM APIs
Without a browser, these APIs do not exist.
Browser JavaScript Main Job
Browser JavaScript's main job is:
- interacting with webpages
- updating UI
- handling clicks
Example:
button.addEventListener("click", () => {
console.log("Clicked");
});
simple life
button clicked
developer happy
user confused why button exists
perfect web development cycle π
What Does Node.js Do?
Node.js main job is to:
- handle servers
- access filesystem
- manage databases
- process requests
Example:
const fs = require("fs");
fs.readFile("data.txt", "utf8", (err, data) => {
console.log(data);
});
So Node.js actually just takes the engine which helps browsers run JavaScript, adds some additional features on top of it, and boom β this is Node.js.
Why Was Node.js Made?
Before Node.js was invented, JavaScript could only run inside browsers.
Backend used other languages like:
- PHP
- Java
- Ruby
- Python
This separation led a man to create Node.js.
BTW do u know who created Node.js?
i know that just its a man (i am not going to say π)
The problem was:
frontend = JavaScript
backend = different language
So developers had to learn multiple languages.
How Node.js Changed Everything
Node.js made it possible to run JavaScript outside the browser.
Which means the same language could now be used for:
- frontend
- backend
Now the same developer learns one language and can build full applications.
and yes developers after this:
βwaitβ¦ i can suffer in only one language now?β
revolutionary moment
The V8 Engine
Now the big chunk of separating JavaScript from the browser and running it outside the browser was made possible by the V8 Engine.
It basically helps compile JavaScript into machine code very efficiently.
V8 was created by Google for Chrome.
This is how the high-level flow looks:
JavaScript Code
β
V8 Engine
β
Machine Code
β
CPU Execution
Important Thing To Know About V8
V8 alone is NOT Node.js.
Node.js adds:
- filesystem access
- networking
- server APIs
- event loop
- operating system interaction
This all happens on top of V8.
This diagram might help:
JavaScript Code
β
Node.js Runtime
β
V8 Engine
β
OS APIs / File System / Network
Additional Features Provided By Node.js
Some additional features provided by Node.js are:
- handling servers
- accessing filesystem
- managing databases
- processing requests
It also helps Node.js handle:
- WebSockets
- chats
- live notifications
- streaming
One of the best things Node.js gave us is NPM (Node Package Manager).
If i start explaining this it would require another blog because it is actually another rabbit hole π
How Node.js Works
Event-Driven Architecture
One of Node.jsβs biggest strengths is Event-driven architecture.
Instead of blocking everything while waiting, Node.js uses events and callbacks.
As u know Node.js is single-threaded, so this part should not act as a disadvantage.
Thatβs why Event-Driven Architecture was introduced.
Traditional Blocking Example
Imagine a server handling:
- file reading
- database query
- API request
Traditional systems may wait for one task to finish before handling another.
Basically:
Do work
Wait
Do next work
Wait again
Cry a little
Repeat
How Node.js Handles This
Node.js works differently.
It says:
βStart task and continue doing other work.β
When the task finishes:
- callback runs
- event triggers
Example:
const fs = require("fs");
fs.readFile("data.txt", "utf8", (err, data) => {
console.log(data);
});
console.log("Other code running");
Output:
Other code running
(file content later)
Node.js does not block execution while waiting for file reading.
Event Loop Idea (Simple)
Task Starts
β
Node.js Continues Other Work
β
Task Finishes
β
Callback Executed
This makes Node.js efficient for:
- concurrent requests
- I/O-heavy applications
- real-time systems
Browser JavaScript vs Node.js
Browser JavaScript
- Runs inside browser
- Uses DOM APIs
- Handles UI
Node.js
- Runs on server
- Uses OS APIs
- Handles backend logic
Conclusion
Node.js transformed JavaScript from:
a browser-only language
into:
a full backend runtime
By combining:
- the V8 engine
- event-driven architecture
- non-blocking I/O
Node.js became one of the most popular backend technologies in the world.
It allowed developers to:
- use JavaScript everywhere
- build scalable applications
- create fast real-time systems
so now this is the end
if u liked the blog please let me know in comments
like the video and subscribe me for more knowledge π
Top comments (0)