Node.js Interview Questions | Eklavya Online

Node.js Interview Questions

What is error-first callback?

Error-first callbacks are used to pass errors and data. If something goes wrong, the programmer has to check the first argument because it is always an error argument. Additional arguments are used to pass data. fs.readFile(filePath, function(err, data) { if (err) { //handle the error } // use the data object });

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

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, …

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

What is an asynchronous API?

All the API’s of Node.js library are asynchronous means non-blocking. A Node.js based server never waits for an API to return data. The Node.js server moves to the next API after calling it, and a notification mechanism of Events of Node.js responds to the server for the previous API call.

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

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 …

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

How can you avoid callbacks?

To avoid callbacks, you can use any one of the following options: You can use modularization. It breaks callbacks into independent functions. You can use promises. You can use yield with Generators and Promises.

Does Node.js provide Debugger?

Yes, Node.js provides a simple TCP based protocol and built-in debugging client. For debugging your JavaScript file, you can use debug argument followed by the js file name you want to debug. Syntax: node debug [script.js | -e “script” |<host>:<port> :]

What is event-driven programming in Node.js?

In Node.js, event-driven programming means as soon as Node starts its server, it initiates its variables, declares functions and then waits for an event to occur. It is one of the reasons why Node.js is pretty fast compared to other similar technologies.