Chapter 1: What is Node.js?
Chapter 1: What is Node.js?
Node.js is a JavaScript runtime environment built on Chrome's V8 engine. It allows JavaScript to run outside the browser, making it a powerful tool for server-side development, CLI tools, desktop apps, and much more.
Key Features of Node.js
a) Runtime Environment
Node.js provides a runtime to execute JavaScript code outside the browser, powered by the V8 engine which compiles JavaScript directly to native machine code.
b) Event-Driven Architecture
Node.js follows an event-driven architecture that efficiently handles asynchronous operations, managing multiple tasks simultaneously without waiting for one to complete.
c) Asynchronous I/O (Non-Blocking I/O)
Node.js performs asynchronous I/O operations — tasks like reading files or making network requests do not block other operations.
// Synchronous (blocking) — traditional model
const data = fs.readFileSync('./file.txt');
console.log(data);
// Asynchronous (non-blocking) — Node.js model
fs.readFile('./file.txt', (err, data) => {
console.log(data);
});
console.log('This runs immediately!');
Development History of Node.js
a) Creation (2009)
Ryan Dahl developed Node.js in 2009, initially experimenting with SpiderMonkey before adopting Google's V8 engine. Originally named web.js, it was later renamed Node.js.
b) Support from Joyent
Joyent saw potential in Node.js and funded Ryan Dahl and the early team, accelerating its development.
Node.js vs Traditional Servers
Before Node.js, most web servers used Apache with a blocking I/O model. Node.js introduced a non-blocking I/O model enabling massive concurrency with fewer resources.
| Feature | Apache (Traditional) | Node.js |
|---|---|---|
| I/O Model | Blocking (synchronous) | Non-blocking (asynchronous) |
| Concurrency | Thread per request | Single thread + Event Loop |
| Language | C / PHP / etc. | JavaScript |
| Memory per connection | High (new thread) | Very low (event callback) |
The Evolution of NPM
NPM (Node Package Manager) is the official package manager for Node.js, letting developers install and manage third-party libraries with a single command.
- 2010 — NPM launched by Joyent for macOS and Linux.
- 2011 — Microsoft collaborated to bring NPM to Windows.
# Install a package
npm install express
# Install globally
npm install -g nodemon
# Run a project
npm start
Leadership and Community Transitions
a) Leadership Changes (2012)
Ryan Dahl stepped down in 2012. Isaac Z. Schlueter, creator of NPM, took over.
b) The io.js Fork and Reunification
In 2014, Fedor Indutny forked Node.js to create io.js due to governance disagreements. By 2015, both communities merged back under the Node.js Foundation.
c) Formation of the OpenJS Foundation (2019)
In 2019, the JS Foundation and Node.js Foundation merged to form the OpenJS Foundation, ensuring long-term community-driven development.