Loading lessons...
Introduction to Node.js Runtime
What is Node.js?
Node.js is an open-source, cross-platform JavaScript runtime environment built on Chrome's V8 JavaScript engine. It allows developers to run JavaScript outside the browser, enabling server-side application development.
Key Characteristics of Node.js
- Single-Threaded: Node.js operates on a single main thread using event-driven execution.
- Non-Blocking I/O: Input/output operations (file reads, database queries, network requests) do not block the execution of subsequent code.
- Asynchronous & Event-Driven: Node.js utilizes callbacks, Promises, and async/await driven by an event loop.
- NPM Ecosystem: Node.js comes bundled with npm (Node Package Manager), the world's largest ecosystem of open-source libraries.
Web Browser vs Node.js
| Feature | Browser Environment | Node.js Environment |
|---|---|---|
| Global Object | window | global |
| DOM Access | Available (document, element) | Unavailable |
| File System Access | Strictly Restricted (Security) | Full Access (fs module) |
| Module System | ES Modules (import/export) | CommonJS (require) & ES Modules |
// hello.js
console.log("Hello from Node.js runtime!");
console.log("Current Process ID:", process.pid);
console.log("Node Version:", process.version);
TL;DR
- Node.js is a server-side JavaScript runtime powered by Chrome's V8 engine.
- It executes JavaScript outside browser boundaries with full operating system access.
- Operates asynchronously with an event-driven architecture.