Sitemap

Introduction to Node.js: The JavaScript Runtime That Powers Modern Web Applications

(Node Series Part 1)

--

This Series will cover Node.js in multiple parts. The idea is to share a basic understanding of Node and start with it.

I am nearly sharing my notes here, which may help u begin Node.

Introductions

Well, why was it even created?

Node.js was created by Ryan Dahl in 2009. Well, the simple answer would be, why not use the existing JavaScript language to make it work on the server side also?

Node.js is a JavaScript runtime that enables us to execute code outside the browser, using non-blocking I/O, an event-driven architecture, and a single-threaded event loop to handle high concurrency efficiently. It uses V8.

What does Node.js solve : Reduces wait time, reduces clock cycle

Here are some major advantages of Node.js and why it was introduced

Non-blocking I/O

Non-blocking I/O is a programming paradigm where a system can handle multiple operations without waiting for one to finish before starting another. Instead of “blocking” (freezing) the execution until a task completes (like reading a file or querying a database), the system delegates the task and moves on to the next operation. When the task finishes, a callback (or promise) is triggered to handle the result.

Real-World Analogy
Blocking I/O: A waiter takes your order, goes to the kitchen, waits for the chef to cook, and only then serves the next customer.
Non-Blocking I/O: The waiter takes your order, tells the chef to start cooking, and immediately helps other customers while your food is prepared. When your meal is ready, the waiter brings it to you.

Event-Based
Like no function should perform direct I/O, to perform an I/O, there must be a callback

Highly Concurrent
Processes multiple tasks interleaved (not truly parallel) via the event loop.
Concurrency means handling multiple tasks in overlapping periods, even if not truly simultaneous.
Achieves concurrency with a single thread (unlike Java/Python multithreading).

Why don’t other languages have it?

Existing Language threads are designed to wait for I/O. It’s not feasible to change the whole model. With the help of libraries, we can achieve this, but again, most of the libraries are not compatible with async io

libuv

  • libuv is a cross-platform, event-driven, asynchronous I/O library written in C
  • It was originally built for Node.js but is now used by many other projects (e.g., Julia, Luvit, uvloop) .

Bridge Between JS and System

V8 (the JS engine) handles executing JavaScript code.

Libuv connects JS to the system-level operations:

  1. Networking (TCP/UDP hooks)
  2. File system (read/write)
  3. DNS, timers, processes, signals

It provides a consistent API across platforms (Linux, macOS, Windows…) .

Event Loop Manager

libuv implements the event loop, built on efficient OS mechanisms such as epoll (Linux),kqueue (macOS/BSD),IOCP (Windows).

Get Shubham Gupta’s stories in your inbox

Join Medium for free to get updates from this writer.

This loop detects when I/O tasks are ready and schedules the corresponding callbacks to run in JS.

Thread Pool for Blocking Tasks

Some operations (like file I/O, DNS resolution) block the OS thread. libuv uses a default pool of 4 background threads to handle these, then notifies the event loop upon completion. This prevents blocking the main JS thread and keeps your Node app responsive.

How Node.js Uses libuv

  1. JS calls fs.readFile(…)
  2. Node’s C++ bridge asks libuv to perform the read operation
  3. libuv schedules it asynchronously — if needed, using a thread pool
  4. When done, libuv signals the event loop
  5. The loop invokes the JS callback

This lets JS stay single-threaded yet still highly concurrent

Pros And Cons

Pros

  1. Built-in HTTP Module. Easy to spin up a server
  2. NPM packages
  3. Non-blocking.

What about Java/PHP/Python/Perl?

These are blocked by default. But with the help of other packages, they can opt for non-blocking IO

Press enter or click to view image in full size
Press enter or click to view image in full size
Press enter or click to view image in full size

Cons

  1. Less CPU Bound
  2. Vulnerable Packages npm audit
  3. Immature JS Developers

If you’d like to be in the know, subscribe, clap, like and share. Cheers!

--

--