NodeJS Questions

Warm up for your NodeJS interview with most asked questions and answers for junior, mid, and senior roles.

Junior

What is the role of assert in Node.js?

Show Answer

Assert is a function which is used to check the condition and throw an error if the condition is false.

Junior

What is Node.js?

Show Answer

Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine. It is used to build fast, scalable network applications.

Junior

Where is Node.js used?

Show Answer

Node. js is primarily used for non-blocking, event-driven servers, due to its single-threaded nature.

Junior

What is Express JS?

Show Answer

Express.js is a free and open-source web application framework for Node.js. It is used for designing and building web applications quickly and easily.

Junior

How Node.js read the content of a file?

Show Answer

Node.js uses the fs module to read the content of a file.

Junior

What is difference between put and patch?

Show Answer

PUT is used to update the existing resource and PATCH is used to update the part of the resource.

Junior

What is the use of yarn in Node.js?

Show Answer

Yarn is a package manager. It is used to install and manage dependencies.

Junior

What is npm in Node.js?

Show Answer

NPM is a package manager. It is used to install and manage dependencies.

Junior

What is difference between JavaScript and Node.js?

Show Answer

JavaScript is a proper high-level programming language used to create web scripts whereas Node. js is a run time environment built on google's v8 engine.

Junior

What is Callback function in node.js?

Show Answer

Callback function is a function which is passed as an argument to another function.

Junior

What is npm?

Show Answer

npm is a package manager for Node.js. It is used to install and manage packages.

Mid

What is the use of EventEmitter in Node.js?

Show Answer

EventEmitter is used to create events and emit events.

The EventEmitter is a module that facilitates communication/interaction between objects in Node. EventEmitter is at the core of Node asynchronous event-driven architecture.

Many of Node's built-in modules inherit from EventEmitter including prominent frameworks like Express.

Mid

Does Node.js supports cryptography?

Show Answer

The node:crypto module provides cryptographic functionality that includes a set of wrappers for OpenSSL's hash, HMAC, cipher, decipher, sign, and verify functions.

Mid

What are buffers in Node.js?

Show Answer
Buffers in Node.js is used to perform operations on raw binary data. Generally, Buffer refers to the particular memory location in memory.
Mid

What is the use of middleware in Node.js?

Show Answer

Middleware is a function that is called before the request is handled by the server. It is used to modify the request and response objects.

Mid

What are global objects in Node.js?

Show Answer

Global objects are objects that are available to all modules in Node.js.

Mid

Why is assert used in Node.js?

Show Answer

Assert is used to check if a condition is true or false.

Mid

What are stubs in Node.js?

Show Answer

Stubs are functions that are used to replace other functions in Node.js.

Mid

What are the timing features of Node.js?

Show Answer
  • setTimeout() Method: The setTimeout() method is used to schedule code execution after a designated amount of milliseconds.
  • setImmediate() Method: The setImmediate() method is used to execute code at the end of the current event loop cycle.
  • setInterval() Method: The setInterval() method is used to call a function at specified intervals (in milliseconds). It is used to execute the function only once after a specified period.
Mid

Are there any disadvantages to using Node.js?

Show Answer

Some of the disadvantages to using Node.js are:

  • Unstable API
  • Lack of Library support
  • High demand for experienced Resources
  • Heavy Computing Tasks
  • Asyncronous Programming Model
Mid

How can you avoid callbacks?

Show Answer

You can avoid callbacks by using promises.

Senior

What are the key features of Node.js?

Show Answer

Asynchronous and Event Driven − All APIs of Node.js library are asynchronous, that is, non-blocking. It essentially means a Node.js based server never waits for an API to return data. The server moves to the next API after calling it and a notification mechanism of Events of Node.js helps the server to get a response from the previous API call.

Very Fast − Being built on Google Chrome's V8 JavaScript Engine, Node.js library is very fast in code execution.

Single Threaded but Highly Scalable − Node.js uses a single threaded model with event looping. Event mechanism helps the server to respond in a non-blocking way and makes the server highly scalable as opposed to traditional servers which create limited threads to handle requests. Node.js uses a single threaded program and the same program can provide service to a much larger number of requests than traditional servers like Apache HTTP Server.

No Buffering − Node.js applications never buffer any data. These applications simply output the data in chunks.

License − Node.js is released under the MIT license.

Senior

What is meant by event-driven programming in Node.js?

Show Answer

Node. js uses event driven programming. It means as soon as Node starts its server, it simply initiates its variables, declares functions and then simply waits for event to occur.

Senior

What is JIT and how is it related to Node.js?

Show Answer

Virtual machine of Nodejs has JIT compilation which improves the execution speed of the code. The virtual machine takes the source code and converts to machine code in runtime.

By this, the hot functions which are called very often are compiled to machine code and, hence increasing speed.

Senior

What is Libuv?

Show Answer

Libuv is a C library that provides a high-level API for asynchronous I/O. It is used to implement the event loop for Node.js.

Senior

What is an event loop in Node.js?

Show Answer

The event loop is what allows Node.js to perform non-blocking I/O operations — despite the fact that JavaScript is single-threaded — by offloading operations to the system kernel whenever possible.