NodeJS
Last updated on
1 min read
Table of Contents
- Event Queue - Whenever an async operation such as reading a file, http request is initiated, node.js doesn’t block the execution of the subsequent code. Instead it registers a callback function and moves on to next instructions
- Event Loop - Continuous process that monitors event queue and the execution stack. If execution stack is empty, then it pricks from event queue and starts executing.
- Execution stack - Keeps track of the execution of functions and program flow. Whenever a function is called a new execution context is created and pushed onto stack. This contains info about local variables, function parameters and the location from where the function was called.
- Event handler - If execution stack is empty, then event loop picks from event queue. After that it calls the associated callback function allowing async operation to complete
- Non Block I/O - When event loop is in progress, the event loop continues to process other events instead of waiting. This enables concurrency and ensures program remains responsive even during heavy I/O operations.
- Timers - Event loop also manages timers and calls callback functions when timer expires.