Skip to main content
Practice Problems

What is Node.js and how does it work?

What is Node.js?

Node.js is a server-side JavaScript runtime built on Chrome's V8 JavaScript engine. It allows you to run JavaScript outside the browser — on servers, desktops, and command-line tools.


Key Characteristics

FeatureDescription
RuntimeBuilt on V8 (Google Chrome's JS engine)
Non-blocking I/OHandles many connections without waiting
Single-threadedOne main thread + event loop
Event-drivenCallbacks/Promises react to events
Cross-platformRuns on Linux, macOS, Windows

How Node.js Works

Your JS Code Node.js APIs (fs, http, crypto…) libuv (C++ library) OS (file system, network, timers…)
  1. V8 compiles your JavaScript to native machine code
  2. libuv provides the event loop and async I/O via a thread pool
  3. Node.js Core APIs bridge JS and the OS

Simple HTTP Server Example

js
const http = require('http'); const server = http.createServer((req, res) => { res.writeHead(200, { 'Content-Type': 'text/plain' }); res.end('Hello, Node.js!'); }); server.listen(3000, () => { console.log('Server running at http://localhost:3000'); });

Why Node.js?

  • Fast — V8 + non-blocking I/O handles thousands of concurrent connections
  • Unified language — JavaScript on both frontend and backend
  • Huge ecosystem — npm has over 2 million packages
  • Great for real-time apps — chat, notifications, streaming
  • Microservices-friendly — lightweight and fast to start

When NOT to Use Node.js

Node.js is not ideal for CPU-intensive tasks (heavy computation, video encoding, image processing) because it runs on a single thread. For those, consider Go, Rust, or use Node.js Worker Threads.


Summary

Node.js = JavaScript runtime + V8 engine + libuv event loop + non-blocking I/O. It excels at I/O-bound tasks (APIs, real-time apps, microservices) and is the foundation of the modern JavaScript backend ecosystem.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.

Finished reading?
Practice Problems