NodeJS Interview Questions and Answers
Question - 61 : - Explain asynchronous and non-blocking APIs in Node.js.
Answer - 61 : -
- 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
Question - 62 : - What is a callback function in Node.js?
Answer - 62 : -
A callback is a function called after a given task. This prevents any blocking and enables other code to run in the meantime.
Question - 63 : - What is REPL in Node.js?
Answer - 63 : -
REPL stands for Read Eval Print Loop, and it represents a computer environment. It’s similar to a Windows console or Unix/Linux shell in which a command is entered. Then, the system responds with an output
Question - 64 : - What is the control flow function?
Answer - 64 : -
The control flow function is a piece of code that runs in between several asynchronous function calls.
Question - 65 : - What is the buffer class in Node.js?
Answer - 65 : -
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
Question - 66 : - What is piping in Node.js?
Answer - 66 : -
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
Question - 67 : - What is callback hell?
Answer - 67 : -
Callback hell, also known as the pyramid of doom, is the result of intensively nested, unreadable, and unmanageable callbacks, which in turn makes the code harder to read and debug
improper implementation of the asynchronous logic causes callback hell
Question - 68 : - What is a reactor pattern in Node.js?
Answer - 68 : -
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
Question - 69 : - What are the different types of HTTP requests?
Answer - 69 : -
HTTP defines a set of request methods used to perform desired actions. The request methods include:
- GET: Used to retrieve the data
- POST: Generally used to make a change in state or reactions on the server
- HEAD: Similar to the GET method, but asks for the response without the response body
- DELETE: Used to delete the predetermined resource
Question - 70 : - What is WASI, and why is it being introduced?
Answer - 70 : -
The WASI class implements the WASI system called API and extra convenience methods for interacting with WASI-based applications. Every WASI instance represents a unique sandbox environment. Each WASI instance must specify its command-line parameters, environment variables, and sandbox directory structure for security reasons.