Introduction to Node.js
What can Node.js Do?
Node.js modules are blocks of code that do not affect other code around them; also, they can be reused repeatedly. Developers can use these built-in modules instead of writing their own, without the need for installation.
Fun Fact #3: Node.js can run without V8; it needs a virtual machine which can be another one, such as ‘Chakra’.
How it Works?
Node.js utilizes a non-blocking event-driven Input/Output, which keeps applications efficient and lightweight, while running on globally distributed devices. Unlike traditional web services, it does not eat up RAM and actually runs single-threaded. The V8 engine uses a data structure (Call Stack) to keep track of functions. When the user requests a function, V8 places a reference on the call stack.
Node.js processes requests in a concurrent cycle, which is referred to as the ‘event loop’. Callbacks are predefined and let the server automatically access the event loop. When callbacks cease, Node exits the event loop. Node process can use different external libraries such as Zlib and C-ares. Therefore, if you encounter any bugs or glitches, they are most probably caused from these external libraries.
Fun Fact #4: You only get one Call stack per Node.js process, so remember to not keep it busy.
Node.js is great for real-time applications having low I/O, for example chat or app monitoring dashboards. On the contrary, it is unfit for heavy server-side computation and processing. It is designed as a single threaded model, so CPU intensive operations will result in blockage of requests on an occupied event loop.
Fun Fact #5: Hosting React applications on Node.js is a common practice, however it is not mandatory for using React.