Node.js Interview Questions and answers

51. What is REPL in Node.js?
Answer : 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.

52. Can a user access DOM in a Node?
Answer : No, you cannot access DOM.

53. What is the difference between Node.js vs Ajax?
Answer : The difference between Node.js and Ajax is that, Ajax (short for Asynchronous Javascript and XML) is a client side technology, often used for updating the contents of the page without refreshing it. While,Node.js is Server Side Javascript, used for developing server software. Node.js does not execute in the browser but by the server.

54. What are the challenges with Node.js ?
Answer : Emphasizing on the technical side, it’s a bit of challenge in Node.js to have one process with one thread to scale up on multi core server.

55. In Node.js, which command is used to import external libraries?
Answer : A command called “require” is used for importing external libraries.

56. What is NPM In Node.Js?
Answer : NPM stands for Node Package Manager. It provides following two main functionalities.
It works as an Online repository for node.js packages/modules which are present at .
It works as Command line utility to install packages, do version management and dependency management of Node.js packages.

57. Explain the tasks of terms used in Node REPL.
Answer : Following are the terms used in REPL with their defined tasks:
Read: It reads users 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.

58. What does it mean “non-blocking” in node.js?
Answer : In node.js “non-blocking” means that its IO is non-blocking. Node uses “libuv” to handle its IO in a platform-agnostic way. On windows, it uses completion ports for unix it uses epoll or kqueue etc. So, it makes a non-blocking request and upon a request, it queues it within the event loop which call the JavaScript ‘callback’ on the main JavaScript thread.

59. What is the command that is used in node.js to import external libraries?
Answer : Command “require” is used for importing external libraries, for example, “var http=require (“http”)”. This will load the http library and the single exported object through the http variable.

60. Mention the framework most commonly used in node.js?
Answer : “Express” is the most common framework used in node.js

61. How to load HTML in Nodejs ?
Answer : To load HTML in Nodejs we have to change the Content-type from text/plain to text/html.

62. What is ‘Callback’ in node.js?
Answer : Callback function is used in node.js to deal with multiple requests made to the server. Like if you have a large file which is going to take a long time for a server to read and if you don’t want a server to get engage in reading that large file while dealing with other requests, call back function is used. Call back function allows the server to deal with pending request first and call a function when it is finished.

63. What is npm? What is the main functionality of npm?
Answer : 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.

64. What are the key features of node.Js?
Answer : Asynchronous event driven IO helps concurrent request handling – All APIs of Node.js are asynchronous. This feature means that if a Node receives a request for some Input/Output operation, it will execute that operation in the background and continue with the processing of other requests. Thus it will not wait for the response from the previous requests.
a. Fast in Code execution – Node.js uses the V8 JavaScript Runtime engine, the one which is used by Google Chrome. Node has a wrapper over the JavaScript engine which makes the runtime engine much faster and hence processing of requests within Node.js also become faster.
b. Single Threaded but Highly Scalable – Node.js uses a single thread model for event looping. The response from these events may or may not reach the server immediately. However, this does not block other operations. Thus making Node.js highly scalable. Traditional servers create limited threads to handle requests while Node.js creates a single thread that provides service to much larger numbers of such requests.
c. Node.js library uses JavaScript – This is another important aspect of Node.js from the developer’s point of view. The majority of developers are already well-versed in JavaScript. Hence, development in Node.js becomes easier for a developer who knows JavaScript.
d. There is an Active and vibrant community for the Node.js framework – The active community always keeps the framework updated with the latest trends in the web development.
e. No Buffering – Node.js applications never buffer any data. They simply output the data in chunks.

65. When should we use node.Js?
Answer : It’s ideal to use Node.js for developing streaming or event-based real-time applications that require less CPU usage such as.
Chat applications.
Game servers.
Node.js is good for fast and high-performance servers, that face the need to handle thousands of user requests simultaneously.

66. What Are Globals In Node.Js?
Answer : The Global keyword represents the global namespace object. It acts as a container for all other objects. If we type <console.log(global)>, it’ll print out all of them.
An important point to note about the global objects is that not all of them are in the global scope, some of them fall in the module scope. So, it’s wise to declare them without using the var keyword or add them to Global object.

67. Explain buffer in Node.js
Answer : The Buffer is a class in Node.js to handle binary data. It is similar to a list of integers but stores as a raw memory outside the V8 heap.
We can convert JavaScript string objects into Buffers. But it requires mentioning the encoding type explicitly.
– Specifies 7-bit ASCII data.
– Represents multibyte encoded Unicode char set.
– Indicates 2 or 4 bytes, little endian encoded Unicode chars.
– Used for Base64 string encoding.
– Encodes each byte as two hexadecimal chars.

68. What is EventEmitter in Node.Js?
Answer : Events module in Node.js allows us to create and handle custom events. The Event module contains “EventEmitter” class which can be used to raise and handle custom events. It is accessible via the following code.

69. How many types of streams are present in node.Js?
Answer : Stream in Node.js are objects that allow reading data from a source or writing data to a specific destination in a continuous fashion. In Node.js, there are four types of streams.
– This is the Stream to be used for reading operation.
– It facilitates the write operation.
– This Stream can be used for both the read and write operations.
– It is a form of a duplex Stream, which performs the computations based on the available input.

Comments are closed here.