Javatpoint Logo



Javatpoint Logo

Node.js Interview Questions

A list of top frequently asked Node.js interview questions and answers are given below.

1) What is Node.js?

Node.js is a Server side scripting which is used to build scalable programs. It is a web application framework built on Google Chrome?s JavaScript Engine. It can be run within the Node.js runtime on Mac OS, Windows and Linux with no changes. This runtime facilitates you to execute a JavaScript code on any machine outside a browser.

2) Is Node.js free to use?

Yes. It is released under MIT license and is free to use.

3) Is Node a single threaded application?

Yes. Node is a single threaded application with event looping.

4) What is the purpose of Node.js?

Node.js can be used for the following purposes:

  • Real time web applications
  • Network applications
  • Distributed systems
  • General purpose applications

5) What are the advantages of Node.js?

Following are the main advantages of Node.js:

  • Node.js is asynchronous and event driven. All API?s of Node.js library are non-blocking and its server doesn't wait for an API to return data. It simply moves to next API after calling it and a notification mechanism of Events of Node.js provides response to the server from the previous API call.
  • Node.js is very fast because it is built on Google Chrome?s V8 JavaScript engine. Its library is very fast in code execution.
  • Node.js is single threaded but highly scalable.
  • Node.js provides a facility of no buffering. Its application never buffers any data. It simply output the data in chunks.

6) What do you understand by the term I/O?

I/O stands for input and output. It will access anything outside of your application. It will be loaded into the machine memory to run the program, once the application is started.

7) How many types of API functions are available in Node.js?

There are two types of API functions in Node.js:

  • Asynchronous, Non-blocking functions
  • Synchronous, Blocking functions

8) 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.

9) 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 next API after calling it and a notification mechanism of Events of Node.js provides response to the server for the previous API call.

10) 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/or Promises.

11) What is a control flow function?

Control flow function is a generic piece of code that runs in between several asynchronous function calls.

12) How "Control Flow" controls the functions calls?

The control flow does the following job:

  • Control the order of execution
  • Collect data
  • Limit concurrency
  • Call the next step in program

13) Is it possible to access DOM in Node?

No, it is not possible to access DOM in Node.

14) What types of tasks can be done asynchronously using the event loop?

  • I/O operations
  • Heavy computation
  • Anything requiring blocking

15) What is REPL in Node.js?

REPL stands for Read Eval Print Loop. It specifies a computer environment like a window console or Unix/Linux shell where you can enter a command and the computer respond with an output.

REPL environment is incorporated with Node.js.

16) Explain the tasks of terms used in Node REPL.

Following are the terms used in REPL with their defined tasks:

Read: It reads user's input; parse the input into JavaScript data-structure and stores in memory.

Eval: It takes and evaluates the data structure.

Print: It is used to print the result.

Loop: It loops the above command until user press ctrl-c twice to terminate.

17) Is it possible to evaluate simple expressions using Node REPL?

Yes. You can evaluate simple expressions using Node REPL.

18) What is the use of underscore variable in REPL?

In REPL, the underscore variable is used to get the last result.

19) What is npm? What is the main functionality of npm?

npm stands for Node Package Manager. Following are the two main functionalities of npm:

  • Online repositories for node.js packages/modules which are searchable on
  • Command line utility to install packages, do version management and dependency management of Node.js packages.

20) What tools can be used to assure consistent style in Node.js?

Following is a list of tools that can be used developing code in teams, to enforce a given style guide and to catch common errors using static analysis.

  • JSLint
  • JSHint
  • ESLint
  • JSCS

21) What is the difference between operational and programmer errors?

Operational errors are not bugs, but create problems with system like request timeout or hardware failure. On the other hand, programmer errors are actual bugs.

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

  • Global installation of dependencies are stored in /npm directory. While local installation of dependencies is stored 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.
  • To install a Node project locally, the syntax is: