Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

1.

What tools can be used to assure consistent code style?

Answer»

ESLINT can be USED with any IDE to ensure a consistent CODING style which further helps in MAINTAINING the codebase. 

2.

What is the purpose of module.exports?

Answer»

This is used to expose functions of a PARTICULAR MODULE or file to be used elsewhere in the project. This can be used to encapsulate all SIMILAR functions in a file which further improves the project structure.

For EXAMPLE, you have a file for all utils functions with util to get solutions in a different programming language of a problem statement.

const getSolutionInJavaScript = ASYNC ({ problem_id}) => {...};const getSolutionInPython = async ({ problem_id}) => {...};module.exports = { getSolutionInJavaScript, getSolutionInPython }

Thus using module.exports we can use these functions in some other file:

const { getSolutionInJavaScript, getSolutionInPython} = require("./utils")
3.

List down the two arguments that async.queue takes as input?

Answer»
4.

How many types of API functions are there in Node.js?

Answer»

There are two TYPES of API functions:

  • ASYNCHRONOUS, non-blocking functions - MOSTLY I/O operations which can be fork out of the main loop.
     
  • Synchronous, blocking functions - mostly operations that INFLUENCE the PROCESS running in the main loop.
5.

How do you create a simple server in Node.js that returns Hello World?

Answer» VAR http = require("http");http.createServer(FUNCTION (request, RESPONSE) { response.writeHead(200, {'Content-Type': 'text/plain'}); response.end('Hello World\n');}).listen(3000);
6.

Why is Node.js single-threaded?

Answer»

Node.js was created explicitly as an EXPERIMENT in async processing. This was to TRY a new theory of doing async processing on a single thread over the existing thread-based IMPLEMENTATION of SCALING via different frameworks.

7.

What is fork in node JS?

Answer»

A fork in general is used to SPAWN child PROCESSES. In node it is used to create a new INSTANCE of V8 engine to RUN multiple workers to execute the code.

8.

What are the advantages of using promises instead of callbacks?

Answer»

The main advantage of using PROMISE is you GET an object to decide the ACTION that needs to be taken after the async task completes. This gives more manageable code and avoids CALLBACK hell.

9.

What are some commonly used timing features of Node.js?

Answer»
  • setTimeout/clearTimeout – This is used to implement DELAYS in code execution.
  • setInterval/clearInterval – This is used to run a code block multiple times.
  • SETIMMEDIATE/clearImmediate – Any FUNCTION passed as the setImmediate() argument is a callback that's executed in the NEXT iteration of the event loop.
  • process.nextTick – Both setImmediate and process.nextTick appear to be doing the same thing; HOWEVER, you may prefer one over the other depending on your callback’s urgency. 
10.

Explain the steps how “Control Flow” controls the functions calls?

Answer»
11.

How is Node.js better than other frameworks most popularly used?

Answer»
  • Node.js provides SIMPLICITY in development because of its non-blocking I/O and even-based model RESULTS in short response time and concurrent processing, unlike other frameworks where developers have to use thread management. 
     
  • It runs on a chrome v8 engine which is WRITTEN in c++ and is highly performant with constant improvement. 
     
  • Also since we will use Javascript in both the frontend and backend the development will be much faster. 
     
  • And at last, there are ample libraries so that we don’t need to reinvent the WHEEL.
12.

How do you manage packages in your node.js project?

Answer»

It can be managed by a number of package installers and their configuration file accordingly. Out of them mostly use npm or yarn. Both PROVIDE almost all libraries of javascript with extended FEATURES of controlling environment-specific configurations. To maintain versions of libs being INSTALLED in a project we use package.json and package-lock.json so that there is no issue in PORTING that APP to a different environment.

13.

What is Node.js and how it works?

Answer»

Node.js is a virtual machine that uses JavaScript as its scripting language and runs Chrome’s V8 JavaScript engine. Basically, Node.js is based on an event-driven architecture where I/O runs asynchronously making it lightweight and efficient. It is being used in DEVELOPING desktop APPLICATIONS as well with a popular FRAMEWORK called electron as it provides API to access OS-level features such as file system, NETWORK, ETC.

14.

What is a first class function in Javascript?

Answer»

When FUNCTIONS can be treated like any other variable then those functions are first-class functions. There are MANY other programming languages, for EXAMPLE, scala, Haskell, ETC which follow this including JS. Now because of this function can be PASSED as a param to another function(callback) or a function can return another function(higher-order function). map() and filter() are higher-order functions that are popularly used.