Node JS Interview Questions
1 .
Explain asynchronous and non-blocking APIs in Node.js.
* All Node.js library APIs are asynchronous, which means they are also non-blocking

* A Node.js-based server never waits for an API to return data. Instead, it moves to the next API after calling it, and a notification mechanism from a Node.js event responds to the server for the previous API call
2 .
What is the control flow function ?
The control flow function is a piece of code that runs in between several asynchronous function calls.
3 .
What is the buffer class in Node.js ?
Buffer class stores raw data similar to an array of integers, but corresponds to a raw memory allocation outside the V8 heap. Buffer class is used because pure JavaScript is not compatible with binary data
4 .
What is piping in Node.js ?
Piping is a mechanism used to connect the output of one stream to another stream. It is normally used to retrieve data from one stream, and pass output to another stream
5 .
What is a reactor pattern in Node.js ?
A reactor pattern is a concept of non-blocking I/O operations. This pattern provides a handler that is associated with each I/O operation. As soon as an I/O request is generated, it is then submitted to a demultiplexer
6 .
Explain the concept of middleware in Node.js.
Middleware is a function that receives the request and response objects. Most tasks that the middleware functions perform are:  
 
* Execute any type of code
* Update or modify the request and the response objects
* Finish the request-response cycle
* Invoke the next middleware in the stack
7 .
Difference between setImmediate() vs setTimeout()
setImmediate() and setTimeout() are similar, but behave in different ways depending on when they are called.

* setImmediate() is designed to execute a script once the current poll (event loop) phase completes.

* setTimeout() schedules a script to be run after a minimum threshold in ms has elapsed.

The order in which the timers are executed will vary depending on the context in which they are called. If both are called from within the main module, then timing will be bound by the performance of the process.
8 .
What is a test pyramid in Node.js ?
In Node.js, a test pyramid is a figure which explains the proportion of unit tests, integrations tests, and end-to-end tests are required for the fruitful development of a project. The components of a test pyramid are given below:
 
Unit Tests : They test the individual units of code in isolation. They are fast and you might perform a lot of these tests

Integrations Tests : They test the integration among dissimilar units.

End-to-End (E2E) Tests : They test the system as a whole, right from the User Interface to the data store, and back.
9 .
What is libuv ?
Libuv, a support library of Node.js, is used for asynchronous Input/output. While it was initially developed just for Node.js, it now witnesses practice with other systems such as Luvit, Julia, Pyuv and more. Some of the features of Libuv are:
 
* File System Events
* Child Processes
* Full-featured event loop backed
* Asynchronous TCP & UDP sockets
10 .
Is Node.js the best platform for CPU-heavy applications ?
Even though Node.js can help in creating server-side applications, CPU-incentive applications are not the strong suit of Node.js. The CPU-heavy operations pave the way for the blockage of incoming requests and push the thread into critical situations.