Node JS Interview Questions and Answers

Node JS Interview Questions and Answers

Last updated on 27th Sep 2020, Blog, Interview Question

About author

Vikram (Sr Technical Project Manager )

He is a Proficient Technical Expert for Respective Industry Domain & Serving 9+ Years. Also, Dedicated to Imparts the Informative Knowledge's to Freshers. He Share's this Blogs for us.

(5.0) | 16547 Ratings 1044

Node.js was initially developed by Ryan Dahl and saw its first release in May 2009. It is a JS environment used to execute JavaScript code outside the browser. Based on Chrome’s V8 engine, it represents the JavaScript anywhere and everywhere programming paradigm, unifying the web app development to a single language rather than different languages for server and client-side scripting.

Many corporate such as LinkedIn, IBM, GoDaddy, Groupon, Netflix, and Paypal use Node.js. Its increasing popularity has sparked a demand for Node.js developers.

1.What is node.js?


  • Node.js is a server side scripting that can be used to create advanced programs. Its many advantages
  • Other server side languages, mainly non-blocking I / O.

2.How does node.js work?


  • Node.js runs in a V8 environment, a virtual machine that uses JavaScript as scripting
  • Language and non-blocking I / O and single threaded events reach high output through the loop.

3.What does the term I / O mean?


  • I / O is the shorthand for input and output, which will access anything outside of your application. This will happen
  • Once the application is started, the machine will be loaded to run the program.

4.What does event-driven programming mean?


  • In computer programming, event driven programming is a programming paradigm with flow.
  • The program is determined by events such as messages from other projects or texts. it is a
  • The application structure technique is split into two sections 1. Event selection 2. Event handling

5.What are some of the most popular modules of Node.js?


There are many most popular, most starred or most downloaded modules in Node.js. Some of them are:

  • express
  • async
  • browserify
  • bower
  • gulp
  • grunt

6.What is the difference between readFile vs createReadStream in Node.js?


  • readFile — is for asynchronously reads the entire contents of a file. It will read the file completely into memory before making it available to the User. readFileSync is a synchronous version of readFile.
  • createReadStream — It will read the file in chunks of the default size 64 kb which is specified beforehand.

7.Types of API functions in Node.js?


Node.js has two types of API functions

  • Asynchronous, non-preventive operations
  • synchronize and prevent operations

8.What is the control flow function?


Many asynchronous functions are known as a common piece of code running between calls Control flow functionality.

9.Explain how “Control Flow” controls functional calls.


  • Control the execution order
  • Collect data
  • integration limit
  • Call the next step in the program

10.Why is Node.js a single thread?


For the Async process, Node.js was created explicitly as a test. It is very much believed Performance and scaling can be achieved through a single oscillation process Typical web loads than regular thread-based implementation.

Subscribe For Free Demo

Error: Contact form not found.

11.Does the node run in windows?


Yes, it does.

12.Can you access the DOM terminal?


No, you can not access the DOM terminal.

13.What are the tasks to do with the use of the Event Ring?


  •  I / O Functions
  •  heavy calculation

14.Why do node.js quickly draw from JavaScript programmers?


  • Node.js draws attention because this is a loop-based server for JavaScript. Node.js gives the user
  • The ability to write javascript on the server, accessing the HTTP stack, file I / O, TCP etc.
  • And databases.

15.What are the two discussions that take async.queue?


Async.queue two arguments

  •  task function
  •  the value of the individual

16.What is an event cycle in Node.js?


Modify call events to activate and manipulate external events Used. So, in the I / O calls, node.js can switch from another request.

17.Can you specify steps that can be single-tuned in Node.js?


You can async Node.js with the following steps

  • First Class Activities
  • Operational system
  •  counters
  •  Event loops

18.What is the benefit of Node.js?



  •  If you do not have any CPU intensive computation in your application, you can create it with JavaScript, If you use JSON Storage Object DB, such as MonGODB, above the database level below,
  •  Crawlers receive a response from a complete HTML code, not a SEO friendship, Single page usage or a websockets app run over Node.js.


  • Any serious CPU calculation prevents the responsiveness of node.js, so there is a distorted base Best approach.
  • Using relational databases associated with Node.js is considered less favorable

19.What is the difference of using var and not using var in REPL while dealing with variables?


Use variables to store values and print later. if var keyword is not used then value is stored in the variable and printed. Whereas if var keyword is used then value is stored but not printed. You can use both variables later.

20.What is the difference between Node.js against Ajax?


The difference between Node.js and Ajax is AJAX (short for Asynchronous JavaScript and XML.

  • Client-side technology is often used to update the contents of the page without refreshing.
  • When Node.js server software javascript, server software is used for developing. Node.js can not be run
  • In the browser but through the server.

21.What are the challenges with Node.js?


  • On the technical side, it’s a bit of a challenge to Node.js to have a process
  • A scalable thread on a multi-core server.

22.What does it mean to be “block-prevention” in node.js?


  • In “Node.js”, “Block-resistance” refers to blocking its IO. The moment uses “libuv” to handle its IO.
  • Site-acoustic way In windows, it utilizes complete ports for Unic, which uses epoll or kueue.
  • Creates an unblock request and puts it within the so-called event ring on the request.
  • JavaScript ‘request’ in the main javascript thread.

23.What is the command used for node.js to export external libraries?


  • The command to import external libraries is “required”, for example, “var http = require (” http “..
  • This will load the HTTP library and the single exported item through the http variable.

24.What is the use of Timers in Node.js?


The Timers module in Node.js contains functions that execute code after a set period of time. Timers do not need to be imported via require(), since all the methods are available globally to emulate the browser JavaScript API.

  • The Node.js API provides several ways of scheduling code to execute at some point after the present moment. The functions below may seem familiar, since they are available in most browsers, but Node.js actually provides its own implementation of these methods.
  • Node.js Timer provides setTimeout(), setImmediate() and setInterval.

25.What is ‘Callback’ in Node.js?


The callback function is used in node.js to handle many of the server’s requests. If you have the following,

  • The server is going to take a long time to read a big file and if you do not want to get a server When dealing with other requests, read that big file and repeat the function. Call the backup function allows the server to cope with the pending request first and a function is called when it is present Concluded.
Course Curriculum

Gain In-Depth Knowledge on Node JS Training from Industry Experts

  • Instructor-led Sessions
  • Real-life Case Studies
  • Assignments
Explore Curriculum

26.What is the relationship of Node.js with JavaScript?


  • Node.js is not a javascript framework, and many of its modules are written here.
  • It allows developers to create new modules for JavaScript.
  • Node.js is a virtual machine, which makes JavaScript to get a high output as a scripting language.

27.What is the use of the DNS module in Node.js?


dns module which provides the underlying system’s name resolution and DNS look up facilities. The DNS module consists of an asynchronous network wrapper.

The most commonly used functions in DNS module are:

  • dns.lookup(address, options, callback) – The dns lookup method takes any website address as its first parameter and returns the corresponding first IPV4 or IPV6 record. The options parameter can be an integer or object. If no options are provided both IPV4 and IPV6 are valid inputs. The third parameter is the callback functions.
  • dns.lookupservice(address, port, callback) – This function converts any physical address such as “” to an array of record types. The record types are specified by the second parameter “rrbyte”. Finally the third method is the callback function.
  • dns.getServers() – This function returns an array of IP address strings, formatted according to rfc5952, that are currently configured for DNS resolution. A string will include a port section if a custom port is used.
  • dns.setServers() – This function sets the IP address and port of servers to be used when performing DNS resolution. The dns.setServers() method must not be called while a DNS query is in progress.

28.Explain the word I / O in the context of Node.js.


I / O has input and output. It is used to access anything outside the application. Once the I / O application is rejected it will be loaded into machine memory to enable programs.

29.What are the security mechanisms available in Node.js?


We can secure our Node.js application in the following ways:

  • Authentication — Authentication is one of the primary security stages at which a user is identified as permitted to access the application at all. Authentication verifies the user’s identity through one or several checks. In Node.js, authentication can be either session-based or token-based. In session-based authentication, the user’s credentials are compared to the user account stored on the server and, in the event of successful validation, a session is started for the user. Whenever the session expires, the user needs to log in again. In token-based authentication, the user’s credentials are applied to generate a string called a token which is then associated with the user’s requests to the server.
  • Error Handling — Usually, the error message contains the explanation of what’s actually gone wrong for the user to understand the reason. At the same time, when the error is related to the application code syntax, it can be set to display the entire log content on the frontend. For an experienced hacker, the log content can reveal a lot of sensitive internal information about the application code structure and tools used within the software.
  • Request Validation — Another aspect which has to be considered, while building a secure Node.js application, is a validation of requests or, in other words, a check of the incoming data for possible inconsistencies. It may seem that invalid requests do not directly affect the security of a Node.js application, however, they may influence its performance and robustness. Validating the incoming data types and formats and rejecting requests not conforming to the set rules can be an additional measure of securing your Node.js application.
  • Node.js Security Tools and Best Practices — We can use tools like helmet (protects our application by setting HTTP headers), csurf (validates tokens in incoming requests and rejects the invalid ones), node rate limiter (controls the rate of repeated requests. This function can protect you from brute force attacks) and cors (enables cross-origin resource sharing).

30.What is the passport in Node.js?


Passport.js is a simple, unobtrusive Node.js authentication middleware for Node.js. Passport.js can be dropped into any Express.js-based web application.

  • Passport recognizes that each application has unique authentication requirements. Authentication mechanisms, known as strategies, are packaged as individual modules. Applications can choose which strategies to employ, without creating unnecessary dependencies.
  • By default, if authentication fails, Passport will respond with a 401 Unauthorized status, and any additional route handlers will not be invoked. If authentication succeeds, the next handler will be invoked and the req.user property will be set to the authenticated user.

31.List the tools and IDEs used for and IDEs used for Node.js.


  • The game
  • Nodeclipse Enide Studio
  • Jet Barton’s West Star
  • JetBrains IntelliJ Idea
  • MS Visual Studio
  • NoFLo

32.Explain the role of the request process in Node.js.


In Node.js, the requested function is used to satisfy many requests from the server. If there is a large file that will take long for the server to perform, you can make a request to ensure that other requests to the server are uninterrupted.

33.What is a bug – first request?


Error-to-use invitations are mainly used to add errors and data. By default, the first argument always refers to a bug, and the user must check if there is anything wrong with it.

34.The difference between functional and programmer errors in the context of Node.js.


Functional errors are not real bugs. They are computer errors, such as “request time” or “hardware error”. Programming errors are the actual errors in the index.

35.What structure is commonly used in Node.js?


The most commonly used Node.js configuration is “Express”.

36.Event-driven programming definition.


This program is a programming example that is characterized by events by news programs of other programs.

37.What are two sections of event driven programming?


Event selection and event handling are two parts of event driven programming.

38.How can you secure your HTTP cookies against XSS attacks?


XSS occurs when the attacker injects executable JavaScript code into the HTML response.

To mitigate these attacks, you have to set flags on the set-cookie HTTP header:

  • HttpOnly – this attribute is used to help prevent attacks such as cross-site scripting since it does not allow the cookie to be accessed via JavaScript.
  • secure – this attribute tells the browser to only send the cookie if the request is being sent over HTTPS.

So it would look something like this: Set-Cookie: sid=<cookie-value>; HttpOnly. If you are using Express, with express-cookie session, it is working by default.

39.Explain the control flow function.


It is a common area code running simultaneously between multiple asynchronous function calls.

40.List the instructions in the Control Flow process.


Limit concurrency is the next program call to collect data to control the order of execution.

41.What is REPL in the context of Node?


REPL stands for Read Eval Print Loop and it represents a computer environment like a window console or unix/linux shell where a command is entered and the system responds with an output. Node.js or Node comes bundled with a REPL environment. It performs the following desired tasks.

  • Read − Read user’s input, parse the input into JavaScript data-structure and store it in memory.
  • Eval − Takes and evaluates the data structure
  • Print − Prints the result
  • Loop − Loops the above command until the user presses ctrl-c twice.

42.How can I access the last expression in Node.js?


Underline the last expression (_. to use the character.

43.What is the biggest drawback of Node.js?


The biggest disadvantage is the fact that it is challenging to process a single thread to measure multiple core servers.

44.Explain REPL at Node.Js


REPL REAL REAL Print Loop It accepts, evaluates, and prints results. REPL provides the UNIX / Linux shell or a window console, which will include the command and the system, as a result we will respond to the output. REPL performs the following tasks.

45.What is the request on Node.Js?


We can call “callback” a coherent equivalent to a call. Node.js utilizes callbacks at large and stimulates the end of the given task. All APIs in Node.js are written to support callbacks.

Course Curriculum

Get Hands-on Node JS Course from Top-Rated Instructors

Weekday / Weekend BatchesSee Batch Details

46.What is a foot blade?


Initially, you can report a reputation after you know about it. Anger hell is a very hard tower, which is hard to read and maintain.

47.How to Avoid Calling on Node.Js


Node.js uses a single threaded event indoors to activate the order processes. But if this approach is running longer than expected, it will prevent the whole process.

48.How many streams are there in Node.Js?


  • <Reader> – This is a stream that can be used for reading activity.
  • <Write> – It makes writing function easier.
  • <Duplex> – This stream can be used to read and write both.
  • <Transform> – This is a double stream format, which calculates the available input.
  • <data> – Removes this event when there is data available to read.
  • <end> – The stream burns this event when there is no more data to read.
  • <error> – This event gun when there is no error reading or writing data.
  • <Filler> – It will fill this event after clearing all the data on the base system.

49.Which of the below statements are true about Node.js?

    1. 1.Node is completely written in JavaScript
    2. 2.Node supports modular JavaScript


Only 2 is true

50.A node application developer is working on an application wherein he has to send a message back to the client from the server. Which among the below methods can he use to implement the same?


  • write(“message”.;

Explore Curriculum

51.Is it free to use Node.js?


Yes! Node.js is released under the MIT license and is free to use.

52.Consider the below code snippet:

  •  url = require(“url”.;
  • function on Request(request, response. { var query=___________________; var name=querystring.parse(query.[“un”]; response.writeHead(200, {“Content-Type”: “text/plain”}.; response.write(“Hello “+name.;}


  • parse(request.url..query

53.on (____, function(data.{var data1=data; }.; Fill the missing code from the options below to get the data from the client using post request.


  • data

54.Which of the below are built-in events in Node?


  • data, end

55.url = require(“url”.;http.createServer(function(request, response. { var url_parts = _________; if(url_parts.pathname==”/login”.  write(“Login Page”.;  response.end(.; } Fill the missing code from the below options.


  • parse(request.url.

56.After successfully installing Node.js on the developer system which of the below commands   can be used to check the version of Node.


  • Node –v

57.Which of the following types of applications can be built in node.js?


Web application, RESTFUL Service, Chat application

58.State TRUE or FALSE – The callback function is a way of synchronous coding execution and get executed following a blocking I/O operation



59.A node.js application is working in an application, wherein he has to send a response back to the client from the server. Which among the below methods can be used to implement the same?


  • end(“message”.;

60.Consider a module test1.js which is placed inside my module folder. Consider another test2.js  file which is placed outside my module folder and given below is its content. What will be the output if the outside test2.js is executed

  • Var  module = require(“./mymodule”.; mymodule(.;


Throws exception

61.Consider the code snippet below: request.on(——, function(data. { var data1 = data;}.; fill the missing code to get the data from the client using POST request.



62.Which of the following is true about EventEmiiter.on(.?


The on(. method is used to bind an event handler with the event.

63.STATE TRUE or FALSE – The ‘querystring’ module in node.js provides methods for parsing and formatting URL query strings.



64.After successfully installing Node.js on the system, which of the below commands can be used to update the NPM version?


  • Npm install npm

65.Why is node.js a single threaded/multi-threaded?


js is a single-threaded for asynchronous processing. With the help of asynchronous processing on a single-thread under typical web loads, leads more the performance and the scalability can be achieved through thread-based implementation.

node js Sample Resumes! Download & Edit, Get Noticed by Top Employers! Download

66.Which one is not a method of EventEmitter class in Node.js?



67.Which of the following is true that the EventEmitter.emit(. function in the Node.js?


emit(. method is used to fire an event.

68.What do you mean by Asynchronous API?


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

69.Which of the most popular frameworks of Node for implementing routing?



70.A node application developer is working on a project specification wherein she needs to read the content of a file while performing other operations. When functioning from the below will she select to perform the same?



71.What is the responsibility for the writeFile method in the FS module?


It replaces the file if it already exists.

Node JS Sample Resumes! Download & Edit, Get Noticed by Top Employers!DOWNLOAD

72.Guess the output of the below code snippet?

  • var fs = require(‘fs’.;
  • fs.readFIle(‘demo.txt”, “UTF8”, (err, content. => console.log(content.; }.;
  • var data = fs.readFileSyce(“demo2.txt”.; console.log(data.toString(..;


Data from demo2.text file data from demo1.txt file

73.Streams should be preferred in which of the following situations


  • File uploads in real time
  • To perform live streaming of video

74.John, a software developer, wants to compress the file using node.js. Which of the following built-in modules he can use to achieve his requirement?



75.What is REPL in Node.js?


  • REPL means Read-Eval-Print-Loop. It is a virtual environment that comes with Node.js. We can uickly test our JavaScript code in the Node.js REPL environment.
  • To launch the REPL in Node.js, just open the command prompt and type node. It will change the prompt to > in Windows and MAC.
  • Now we can type and run our JavaScript easily. For example, if we type 10 + 20, it will print 30 in the next line.

76.The statement is true regarding the TCP server?


TCP server can send data to the client

77.Which method is used to create a TCP server?



78.Which built-in module can be used for socket programming?



79.Which mode of installation is better to install any package which has an application dependency?



80.The correct statement regarding npm


  • Npm is the default package manager bundled with node.js
  • Open-source developers use npm to share and borrow packages
  • Packages are structured to keep track of dependencies and version in npm

81.A node application developer is working on a project requirement wherein he needs to have a node module to be available across the command line. Which among the commands will he use to install the module?


  • npm install modulename – g

82.John wants to check the version of NPM. Which command line can he use to meet his requirement?


  • npm – v

83.Which of the following is a drop-in replacement of NPM?



84.The package.json file can contain which of the following information?


  • Module name
  • License

85.Which command is used to create the package.json file?


npm init

86.The “npm install” command installs the dependencies present in package.json file in the node_modules folder. Is state true or false?



87.Consider the code below written for connection the MYSQL database

  • var client = sl.createConnection({ host: “localhost”, user: “root” }.;
  • client.connect(.;
  • client.query(“use bookDB”.;

which is true in the above code?


Throws error if the DB does not exist

88.Select the object data modeling library for MongoDB used in node applications?



89.What are the benefits of using Node.js?


Following are main benefits of using Node.js

  • Asynchronous and Event DrivenAll 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. Server moves to the next API after calling it and a notification mechanism of Events of Node.js helps the server to get 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 servers to respond in non-blocking ways and makes servers 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 service a much larger number of requests than a traditional server like Apache HTTP Server.
  • No Buffering − Node.js applications never buffer any data. These applications simply output the data in chunks.

90.A node application developer is working on a requirement wherein she needs to connect to another web application to execute a specific logic. Which among them will select to do the same?


Make a rest call to the other application using restler module

91.A node application developer is working on a project specification wherein she needs to save the data to the database using another application. Which among them do the same?


Make an HTTP post request to a restful web service.

92.A node application developer is working on a requirement wherein she needs to create a child process to execute a set of code in her application. Which will she make use to achieve the same?



93.A node application developer is working on an application, wherein she has to do load balancing between child processes. Which node module will she select to implement the same?



94.———- method the specialized form of spawn(. method to create the child process?



95.Harry, a node application developer wants to run a python script from node.js. Is it possible for him to achieve his requirement using a child process module?



96.Which command is used to inert the breaking point in a node application?



97.Which is used to give a graphical user interface to perform node application debugging?


V8 inspector

98.Which is used to watch the changes occurring inside a given directory and restart the node application after each change?



99.js asynchronous/ synchronous?



100.Why is Node.js single threaded?


For async processing, Node.js was created explicitly as an experiment. It is believed that more performance and scalability can be achieved by doing async processing on a single thread under typical web loads than the typical thread based implementation.

101.Is Node.js is front end/back end?


js is not front end or back end. It is a combination of the runtime environment and javascript library

Are you looking training with Right Jobs?

Contact Us

Popular Courses