Node.js Interview Questions

What is the Punycode in Node.js?

Post Views: 37,652 The Punycode is an encoding syntax which is used to convert Unicode (UTF-8) string of characters to ASCII string of characters. It is bundled with Node.js v0.6.2 and later versions. If you want to use it with other Node.js versions, then use npm to install Punycode module first. You have to used require (‘Punycode’) to access it. Syntax: punycode = require(‘punycode’);

Read More

What is the difference between events and callbacks in Node.js?

Post Views: 37,652 Although, Events and Callbacks look similar the differences lies in the fact that callback functions are called when an asynchronous function returns its result whereas event handling works on the observer pattern. Whenever an event gets fired, its listener function starts executing. Node.js has multiple in-built events available through the events module and EventEmitter class which is used to bind events and event listeners.

Read More

What are the streams in Node.js?

Post Views: 37,645 The Streams are the objects that facilitate you to read data from a source and write data to a destination. There are four types of streams in Node.js: Readable: This stream is used for reading operations. Writable: This stream is used for write operations. Duplex: This stream can be used for both reading and write operations. Transform: It is a type of duplex stream where the output computes according to input.

Read More

What is the role of assert in Node.js?

Post Views: 37,642 The Node.js Assert is a way to write tests. It provides no feedback when running your test unless one fails. The assert module provides a simple set of assertion tests that can be used to test invariants. The module is intended for internal use by Node.js, but can be used in application code via require (‘assert’).

Read More

What is the use of a buffer class in Node.js?

Post Views: 37,635 The Node.js provides Buffer class to store raw data similar to an array of integers but corresponds to a raw memory allocation outside the V8 heap. It is a global class and can be accessed in an application without importing a buffer module. Buffer class is used because pure JavaScript is not compatible with binary data. So, when dealing with TCP streams or the file system, it’s necessary to handle octet streams.

Read More

What is the difference between the global installation of dependencies and local installation of dependencies?

Post Views: 37,629 Global installation of dependencies is stored in /npm directory. While local installation of dependencies stores in the local mode. Here local mode refers to the package installation in node_modules directory lying in the folder where Node application is present. Globally deployed packages cannot be imported using require() in Node application directly. On the other hand, locally deployed packages are accessible via require(). To install a Node project globally -g flag is used. C:\Nodejs_WorkSpace>npm install express ?g To…

Read More