OSSTube

Node.js Uses every phases

Technology
8 min read
Harshit
Harshit
8 min read

June 23, 2025

0

0

6

Node.js 24: What’s New?

1. V8 Engine Upgrade (v13.6)

Node.js 24 incorporates V8 version 13.6, introducing powerful features like Float16Array for 16-bit floats, RegExp.escape, Node.js Documentation WebAssembly Memory64, Error.isError, and explicit resource management syntax (using, await using).

These additions streamline modern JS patterns and facilitate memory-efficient coding.

2. npm 11 & Undici 7

The bundled npm 11 delivers elevated package performance and security enhancements.

Meanwhile, Undici 7 brings Node.js Documentation optimized HTTP/1.1 & HTTP/2 capabilities, faster connection pooling, WebSocket improvements, and robust retry mechanisms—boosting HTTP efficiency by up to 30%.

3. Async Context & Permission Model Refinement.

AsyncLocalStorage now defaults to AsyncContextFrame, offering lighter, more reliable async context Node.js Documentation propagation.

The experimental permission model matures—flagged now as --permission—allowing developers to restrict filesystem, network, or environment access, bolstering security.

4. URLPattern, Structured Clone & Core API Cleanup.

URLPattern becomes globally available, making URL matching concise and powerful.

Full support for structuredClone, ESM Node.js Documentation improvements, updates to fs and crypto, and deprecation of legacy APIs (like process.binding()) and modules round out this release’s developer-friendly polishing.

Node.js Uses Diagram
Node.js Uses Diagram

Deep Dive: Node.js Event Loop Lifecycle

Initialization & Core Purpose

When a Node.js application starts, it first runs all synchronous code before entering the event loop, powered by libuv. The call stack drains to zero, and then the loop continuously manages asynchronous I/O, timers, and callbacks.

The loop persists until no callbacks remain and no pending operations are left.

Macro-Task vs Micro-Task Queuing.

The event loop consists of phases for macro-tasks—timers (setTimeout, setInterval), pending callbacks, I/O polling, setImmediate, and close callbacks—and micro-tasks (process.nextTick() and Promises), which always run first in each cycle.micro-tasks execute immediately after the current callback, ensuring prompt resolution before moving to the next phase.

Phase Breakdown & Behavior:

Timers: Executes callbacks whose delay has passed.

Pending callbacks: Handles deferred I/O callbacks like TCP errors.

Poll: Retrieves and executes I/O events; can block waiting for events.

Check: Processes setImmediate() callbacks.

Close callbacks: Acts on close events like socket termination.

During each phase, micro-tasks are executed between callbacks to keep the queue clean and responsive

Integration with Threads & Non-blocking I/O:

Heavy I/O or CPU-heavy operations are offloaded via libuv’s C++ thread-pool or relying on OS-level async interfaces. When these tasks complete, their callbacks are queued (often entering the poll or pending callback phase) once the call stack clears.

This model enables high concurrency without multiple threads.

Event Loop Advantages and Pitfalls.

This design avoids thread-switching overhead and scales effectively for I/O-bound workloads . However, long-running synchronous operations can starve the event loop, delaying timers or pending callbacks—so developers must avoid blocking via heavy loops or synchronous code.

Metrics like loop latency should be monitored to keep applications responsive.

Final Thoughts

Node.js 24 gives developers modern JavaScript capabilities, stronger async context tools, and better security. Understanding the finely tuned mechanics of the event loop unlocks performance optimizations and prevents common pitfalls. With thoughtful use, Node.js remains a top-tier runtime for scalable, high-performance apps.

Tags
Node.js
Performance
JavaScript
Harshit
About Harshit

Full-stack developer 1+ years of experience in Node.js and modern web technologies.

6 views

0 shares

Trending

navbarlogoimage
Mobile: +91 8826844273Email: [email protected]

OSSTube

About usPrivacy PolicyTerms

NEWSLETTER

If you wanted to know more details please share email with us...