Open In App

Node Interview Questions and Answers (2024) – Intermediate Level

Last Updated : 08 Feb, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

In this article, you will learn NodeJS interview questions and answers intermediate level that are most frequently asked in interviews. Before proceeding to learn NodeJS interview questions and answers – intermediate level, first learn the complete NodeJS Tutorial, and NodeJS Interview Questions and Answers – Beginner Level.

NodeJS is an open-source and cross-platform runtime environment built on Chrome’s V8 JavaScript engine for executing JavaScript code outside of a browser. You need to recollect that NodeJS isn’t a framework, and it’s not a programing language. It provides an event-driven, non-blocking (asynchronous) I/O and cross-platform runtime environment for building highly scalable server-side applications using JavaScript.

NodeJS Interview Questions & Answers

Pre-requisite: NodeJS Interview Questions and Answers (2024) – Beginner Level

Similar Article: NodeJS Interview Questions and Answers (2024) – Advanced Level

This set contains the intermediate-level questions asked in the interview.

1. What is event-driven programming in Node.js?

Event-driven programming is used to synchronize the occurrence of multiple events and to make the program as simple as possible. The basic components of an Event-Driven Program are:

  • A callback function ( called an event handler) is called when an event is triggered.
  • An event loop that listens for event triggers and calls the corresponding event handler for that event.

2. What is buffer in Node.js?

The Buffer class in Node.js is used to perform operations on raw binary data. Generally, Buffer refers to the particular memory location in memory. Buffer and array have some similarities, but the difference is array can be any type, and it can be resizable. Buffers only deal with binary data, and it can not be resizable. Each integer in a buffer represents a byte. console.log() function is used to print the Buffer instance.

3. What are streams in Node.js?

Streams are a type of data-handling method and are used to read or write input into output sequentially. Streams are used to handle reading/writing files or exchanging information in an efficient way. The stream module provides an API for implementing the stream interface. Examples of the stream object in Node.js can be a request to an HTTP server and process.stdout are both stream instances.

4. Explain crypto module in Node.js

The crypto module is used for encrypting, decrypting, or hashing any type of data. This encryption and decryption basically help to secure and add a layer of authentication to the data. The main use case of the crypto module is to convert the plain readable text to an encrypted format and decrypt it when required.

5. What is callback hell?

Callback hell is an issue caused due to a nested callback. This causes the code to look like a pyramid and makes it unable to read To overcome this situation we use promises.

6. Explain the use of timers module in Node.js

The Timers module in Node.js contains various functions that allow us to execute a block of code or a function after a set period of time. The Timers module is global, we do not need to use require() to import it. 

It has the following methods:

7. Difference between setImmediate() and process.nextTick() methods

The process.nextTick() method is used to add a new callback function at the start of the next event queue. it is called before the event is processed. The setImmediate is called at the check phase of the next event queue. It is created in the poll phase and is invoked during the check phase.

8. What is the difference between setTimeout() and setImmediate() method?

The setImmediate function is used to execute a particular script immediately whereas the setTimeout function is used to hold a function and execute it after a specified period of time.

9. What is the difference between spawn() and fork() method?

Both these methods are used to create new child processes the only difference between them is that spawn() method creates a new function that Node runs from the command line whereas fork() function creates an instance of the existing fork() method and creates multiple workers to perform on the same task.

10. Explain the use of passport module in Node.js

The passport module is used for adding authentication features to our website or web app. It implements authentication measure which helps to perform sign-in operations.

11. What is fork in Node.js?

Fork is a method in Node.js that is used to create child processes. It helps to handle the increasing workload. It creates a new instance of the engine which enables multiple processes to run the code.

12. What are the three methods to avoid callback hell?

The three methods to avoid callback hell are:

  • Using async/await()
  • Using promises
  • Using generators

13. What is body-parser in Node.js?

Body-parser is the Node.js body-parsing middleware. It is responsible for parsing the incoming request bodies in a middleware before you handle it. It is an NPM module that processes data sent in HTTP requests.

14. What is CORS in Node.js?

The word CORS stands for “Cross-Origin Resource Sharing”. Cross-Origin Resource Sharing is an HTTP-header based mechanism implemented by the browser which allows a server or an API to indicate any origins (different in terms of protocol, hostname, or port) other than its origin from which the unknown origin gets permission to access and load resources. The cors package available in the npm registry is used to tackle CORS errors in a Node.js application.

15. Explain the tls module in Node.js?

The tls module provides an implementation of the Transport Layer Security (TLS) and Secure Socket Layer (SSL) protocols that are built on top of OpenSSL. It helps to establish a secure connection on the network.

16. What is the use of url module in Node.js?

In Node.js url module is used to split the URL of the website into parts so that it becomes readable and can be used in the different parts of the application. The parse() method is used with the url module to separate the URL of the website into parts.

17. What is REST API?

Representational State Transfer (REST) is an architectural style that defines a set of constraints to be used for creating web services. REST API is a way of accessing web services in a simple and flexible way without having any processing. It works after the request is sent from the client to the server in the form of a web URL as HTTP GET or POST or PUT or DELETE request. After that, a response comes back from the server in the form of a resource which can be anything like HTML, XML, Image, or JSON. But now JSON is the most popular format being used in Web Services. 

18. Explain the engine Google uses for Node.js

The engine used by Google for Node.js is V8. It is one the fastest engine as it is written in C++. It provides a runtime environment for the execution of JavaScript code. The best part is that the JavaScript engine is completely independent of the browser in which it runs. It has a huge community and is highly portable.

19. Name the tool used for writing consistent code

ESLint is a tool used in many IDEs to write consistent code styles. ESLint is written using Node.js to provide a fast runtime environment and easy installation via npm.

20. What are the different kinds of HTTP requests?

The most commonly used HTTP requests are:

  • GET: This request is used to read/retrieve data from a web server. GET returns an HTTP status code of 200 (OK) if the data is successfully retrieved from the server.
  • PUT: This request is used to modify the data on the server. It replaces the entire content at a particular location with data that is passed in the body payload. If there are no resources that match the request, it will generate one.
  • POST: This request is used to send data (file, form data, etc.) to the server. On successful creation, it returns an HTTP status code of 201.
  • DELETE: This request is used to delete the data on the server at a specified location.


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads