Introduction
Node.js is an open-source, cross-platform JavaScript runtime built on Google's V8 engine. It allows developers to run JavaScript code outside of a web browser, most commonly on a server. Before Node.js, JavaScript was almost exclusively a client-side scripting language used to add interactivity to web pages. Node.js changed that by giving JavaScript access to the file system, network, and operating system, enabling developers to build full backend applications, command-line tools, and APIs using a single language across the entire stack.
Cricket analogy: Before Node.js, JavaScript was like a player who could only bat in exhibition matches (browsers); Node.js let that same player join the full squad, bowling and fielding too, by giving JS access to the file system and network.
Node.js was created by Ryan Dahl in 2009. Its defining design choice was to be non-blocking and event-driven, which makes it especially well suited for I/O-heavy applications such as web servers, real-time chat applications, and streaming services.
Cricket analogy: Ryan Dahl designing Node.js as non-blocking is like a captain designing a fielding strategy around quick reflexes rather than waiting idly, which is why Node thrives in fast, I/O-heavy scenarios like live streaming.
How It Works
Node.js embeds the V8 JavaScript engine (also used in Google Chrome) to compile and execute JavaScript directly to machine code. On top of V8, Node.js adds a set of built-in APIs (modules like fs, http, path) written in C++ and JavaScript that expose operating system features. Node.js uses libuv, a C library, to handle asynchronous, non-blocking I/O operations and to provide the event loop, thread pool, and cross-platform abstractions for file system and network operations.
Cricket analogy: V8 is like the bat that translates a swing into runs; Node's built-in modules are like the coaching staff (fs, http, path) providing structure, while libuv is like the ground crew handling weather delays and pitch conditions behind the scenes.
// hello.js
console.log('Hello from Node.js!');
console.log('Node version:', process.version);Explanation
The example above is a plain JavaScript file with no browser-only APIs like window or document. Instead, it uses process, a global object provided by Node.js that gives information about the currently running process, such as the Node.js version, command-line arguments, and environment variables. Running this file with the node command executes it directly using the V8 engine, without needing a browser.
Cricket analogy: A player using field-specific gear like spikes and pads (Node's process object) instead of casual sneakers (browser APis like window) is equipped for the actual playing surface, running the file directly rather than through a browser.
Example
node hello.jsOutput
Hello from Node.js!
Node version: v20.11.1Key Takeaways
- Node.js is a JavaScript runtime built on Chrome's V8 engine, not a framework or language.
- It lets JavaScript run outside the browser, enabling server-side and command-line applications.
- Node.js uses an event-driven, non-blocking I/O model, making it efficient for I/O-heavy workloads.
- libuv provides the event loop and handles asynchronous operations under the hood.
- Common use cases include REST APIs, real-time apps, microservices, and build tooling.
Practice what you learned
1. What is Node.js?
2. Who created Node.js and in what year?
3. Which library does Node.js use to implement its event loop and async I/O?
4. Which of the following is a typical use case for Node.js?
Was this page helpful?
You May Also Like
Node.js Architecture and the Event Loop
Understand Node.js's single-threaded, non-blocking architecture and how the event loop phases process callbacks.
npm and Package Management
Learn how npm manages dependencies, scripts, and versioning for Node.js projects via package.json.
Setting Up a Node.js Environment
Install Node.js, choose an LTS version, and configure a basic project structure ready for development.
Related Reading
Related Study Notes in Web Development
Browse all study notesWebSockets Study Notes
Web Development · 30 topics
Web DevelopmentWebAssembly Study Notes
WebAssembly · 30 topics
Web DevelopmentgRPC Study Notes
Protocol Buffers · 30 topics
Web DevelopmentSpring Boot Study Notes
Java · 30 topics
Web DevelopmentFlask Study Notes
Python · 30 topics
Web DevelopmentDjango Study Notes
Python · 30 topics