X Tutup
Skip to content

Meeth-webdev/Advance-NodeJs

Repository files navigation

Advanced Node.js Learning Notes

This repository contains my learnings and experiments while exploring Advanced Node.js concepts.


🚀 What I Learned

1. What is Node.js?

  • 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)

2. V8 and Alternatives

  • V8 is the default engine used by Node.js.
  • Other JavaScript engines include:
    • Chakra (used by Microsoft Edge)
    • SpiderMonkey (used by Firefox)

3. File System (fs) Module

  • 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.

4. Node.js: Single-Threaded but Multi-Threaded

  • 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.

5. Thread Pooling

  • 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.

6. Event Loop

  • 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.

📘 Summary

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.

🔗 Next Steps

  • Explore Streams & Buffers in Node.js.
  • Learn Cluster & Worker Threads for scaling applications.
  • Deep dive into Node.js performance optimization.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

X Tutup