DEV Community

Cover image for What is Node.js? JavaScript on the Server
Shivam Yadav
Shivam Yadav

Posted on

What is Node.js? JavaScript on the Server

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");
Enter fullscreen mode Exit fullscreen mode

All these things only work because browsers provide:

  • document
  • window
  • 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");
});
Enter fullscreen mode Exit fullscreen mode

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);
});
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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");
Enter fullscreen mode Exit fullscreen mode

Output:

Other code running
(file content later)
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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)