Google News
NodeJS Interview Questions
Built on top of Node.js, ExpressJS is a JS framework used to manage the flow of information between the routes and server in server-side apps. Being lightweight, flexible and filled with a variety of relevant features, it is apt for mobile and web application development.
Long Term Support or LTS version/releases of Node.js are the releases which receive all the critical fixes, performance step ups and security updates. These versions receive support for at least 1.5 years and have a focus on security and stability of the application.
Assert is used to write tests in Node.js. The feedback is provided only if any of the test cases that are running fails. To test invariants, the module gives you a set of assertion tests. It is used internally by Node.js, but if you use require (‘assert’) code, you will be able to use it in other applications as well.
In Node.js, streams are the collection of data similar to strings and arrays. Moreover, streams are objects through which you can read source data or write destination data continuously. These streams are particularly helpful for reading and processing large amounts of information. There are four types of streams in Node.js, which are:
Readable : Used to read large amount of data from source

Writeable : Used to write data to destination

Duplex : Used for both read and write

Transform : A duplex stream used for data modification
A timer module containing multiple functions for the execution of the code after a specific time period is provided by Node.js. Some of the functions provided in this module are:
process.nextTick : This function schedules a callback function which is required to be invoked in the next iteration of the event loop

setTimeout/clearTimeout : This function schedules code execution after the assigned amount of time (in milliseconds)

setImmediate/clearImmediate : This functions executes code at the conclusion of the existing event loop cycle

setInterval/clearInterval : This function is used to execute a block of code a number of times
Both process.nextTick() and setImmediate() are functions of the Timers module, but the difference lies in their execution.
The process.nextTick() function waits for the execution of action till the next pass around in the event loop or when the event loop culminates, then only the callback function is invoked.

The setImmediate() function is used for callback method execution on the next cycle of the event loop, which returns it to the event loop for the execution of the input/output operations.
A built-in TCP protocol and the debugging client is provided by Node.js. If you wish to debug your file, you can use the following argument before the name of your JS file which you wish to debug.
node debug [script.js | -e “script” | :]
Following code snippet can be used to make a Post Request in Node.js.
var request = require('request');
{ form: { key: 'value' } },
function (error, response, body) {
if (!error && response.statusCode == 200) {
The one common trait between Node.js, AJAX, and jQuery is that all of them are the advanced implementation of JavaScript. However, they serve completely different purposes.
Node.js : It is a server-side platform for developing client-server applications. For example, if we’ve to build an online employee management system, then we won’t do it using client-side JS. But the Node.js can certainly do it as it runs on a server similar to Apache, Django not in a browser.
AJAX (aka Asynchronous Javascript and XML) : It is a client-side scripting technique, primarily designed for rendering the contents of a page without refreshing it. There are a no. of large companies utilizing AJAX such as Facebook and Stack Overflow to display dynamic content.
jQuery : It is a famous JavaScript module which complements AJAX, DOM traversal, looping and so on. This library provides many useful functions to help in JavaScript development. However, it’s not mandatory to use it but as it also manages cross-browser compatibility, so can help you produce highly maintainable web applications.
Events module in Node.js allows us to create and handle custom events. The Event module contains “EventEmitter” class which can be used to raise and handle custom events. It is accessible via the following code.
// Import events module
var events = require('events');
// Create an eventEmitter object
var eventEmitter = new events.EventEmitter();

When an EventEmitter instance encounters an error, it emits an “error” event. When a new listener gets added, it fires a “newListener” event and when a listener gets removed, it fires a “removeListener” event.
EventEmitter provides multiple properties like “on” and “emit”. The “on” property is used to bind a function to the event and “emit” is used to fire an event.