Node JS Interview Questions and Answers Set 10

91. What are the features of Node.js?

Node.js is a single-threaded but highly scalable system that utilizes JavaScript as its scripting language. It uses asynchronous, event-driven I/O instead of separate processes or threads. It is able to achieve high output via single-threaded event loop and non-blocking I/O.

92.Why is Node.js Single-threaded?

Node.js is single-threaded for async processing. By doing async processing on a single-thread under typical web loads, more performance and scalability can be achieved as opposed to the typical thread-based implementation.

93.What is the difference between Node.js and Ajax?

Node.js and Ajax (Asynchronous JavaScript and XML) are the advanced implementation of JavaScript. They all serve completely different purposes.

Ajax is primarily designed for dynamically updating a particular section of a page’s content, without having to update the entire page.

Node.js is used for developing client-server applications.

94.Why is consistent style important and what tools can be used to assure it?

Consistent style helps team members modify projects easily without having to get used to a new style every time. Tools that can help include Standard and ESLint.

95. How Will You Truncate A File Using Node?

Following is the syntax of the method to truncate an opened file:

fs.ftruncate(fd, len, callback)

Parameters

Here is the description of the parameters used:

fd – This is the file descriptor returned by file fs.open() method.

len – This is the length of the file after which file will be truncated.

callback – This is the callback function which gets no arguments other than a possible exception are given to the completion callback.

NODE JS & CERTIFICATION
Weekend / Weekday Batch

96. Which Module Is Used For Buffer Based Operations?

buffer module is used for buffer based operations.

var buffer = require(“buffer”)

97. What Is A Blocking Code?

If application has to wait for some I/O operation in order to complete its execution any further then the code responsible for waiting is known as blocking code.

98.What Is Event Loop?

Node js is a single threaded application but it support concurrency via concept of event and callbacks. As every API of Node js are asynchronous and being a single thread, it uses async function calls to maintain the concurrency. Node uses observer pattern. Node thread keeps an event loop and whenever any task get completed, it fires the corresponding event which signals the event listener function to get executed.

99.What Is Purpose Of Buffer Class In Node?

Buffer class is a global class and can be accessed in application without importing buffer module. A Buffer is a kind of an array of integers and corresponds to a raw memory allocation outside the V8 heap. A Buffer cannot be resized.

100.Which Module Is Used For Web Based Operations?

http module is used for web based operations.

var http = require(“http”)