Google News
logo
NodeJS Interview Questions
* 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
The control flow function is a piece of code that runs in between several asynchronous function calls.
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
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
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
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
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.
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.
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
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.