This repository contains my learnings and experiments while exploring Advanced Node.js concepts.
- Node.js is a JavaScript runtime built on Google’s V8 engine.
- It acts as a bridge between JavaScript and lower-level system code by combining:
- JavaScript (the language we write in)
- V8 (JavaScript engine that compiles JS to machine code)
- libuv (library that provides event loop, async I/O, and thread pool)
- C++ bindings (for system-level operations)
- V8 is the default engine used by Node.js.
- Other JavaScript engines include:
- Chakra (used by Microsoft Edge)
- SpiderMonkey (used by Firefox)
- Explored how
fs.readFile(asynchronous) works under the hood using libuv. - Compared with
fs.readFileSync(synchronous). - Learned how Node.js internally calls C++ code for system-level file operations.
- Also checked OS-level documentation related to file system operations.
- Node.js appears single-threaded to developers because JavaScript runs on a single main thread.
- Under the hood, Node.js uses a thread pool (via libuv) for operations like:
- File system tasks
- Network requests
- Cryptography
- This makes Node.js asynchronous and efficient.
- Learned how libuv manages a pool of worker threads.
- Tasks like I/O or heavy computations are delegated to the thread pool while the main thread stays free.
-
Understood the event-driven architecture of Node.js.
-
Studied how the event loop manages execution with:
- Call Stack
- Callback Queue / Task Queue
- Microtask Queue (Promises,
process.nextTick) - Web APIs
- RAF Queue (requestAnimationFrame in browsers)
-
Solved tough questions on:
- Execution order of callbacks, promises, and microtasks.
- Visualization of how the event loop cycles through tasks.
Through this learning process, I understood:
- How Node.js connects JavaScript with C++ through V8 and libuv.
- The difference between synchronous vs asynchronous execution.
- Why Node.js is single-threaded in JavaScript but multi-threaded under the hood.
- The event loop and how it makes Node.js non-blocking and scalable.
- Explore Streams & Buffers in Node.js.
- Learn Cluster & Worker Threads for scaling applications.
- Deep dive into Node.js performance optimization.