Node Js Interview Questions And Answers Pdf

1. What is Node.js? Where can you use it?
Answer: Node.js is server-side scripting based on Google’s V8 JavaScript engine. It is used to build scalable programs especially web applications that are computationally simple but are frequently accessed.
You can use Node.js in developing I/O intensive web applications like video streaming sites. You can also use it for developing: Real-time web applications, Network applications, General-purpose applications, and Distributed systems.

2. 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.

3. Which types of application developed using Node js?
Answer: You can develop Real-time web applications, Network applications, Distributed Systems, and General-purpose applications using the Node js.

4. What is the Punycode in Node.js?
Answer: The Punycode is an encoding syntax which is used to convert Unicode (UTF-8) string of characters to ASCII string of characters. It is bundled with Node.js v0.6.2 and later versions. If you want to use it with other Node.js versions, then use npm to install the Punycode module first. You have to used require (‘Punycode’) to access it.

5. What are the functionalities of NPM in Node.js?
Answer:
NPM (Node Package Manager) provides two functionalities:
An online repository for Node.js packages
Command-line utility for installing packages, version management and dependency management of Node.js packages

6. Explain REPL In Node.Js?
Answer: The REPL stands for “Read Eval Print Loop”. It is a simple program that accepts the commands, evaluates them, and finally prints the results. REPL provides an environment similar to that of Unix/Linux shell or a window console, in which we can enter the command and the system, in turn, responds with the output. REPL performs the following tasks.
READ
It reads the input from the user, parses it into JavaScript data structure and then stores it in the memory.
EVAL
It Executes the data structure.
PRINT
It Prints the result obtained after evaluating the command.
LOOP
It Loops the above command until the user presses Ctrl+C two times.

7. In which Language Node Js is written?
Answer: Node js is written in C, C++,JavaScript.It uses Google’s open source V8 Javascript Engine to convert Javascript code to C++. (node js interview questions and answers pdf)

8. What you mean by chaining in Node.JS?
Answer: It’s a mechanism in which output of one stream will be connected to another stream and thus creating a chain of multiple stream operations.

9. Why should you use Node.js?
Answer: Scalable network programs can be developed easily by Node.js and if you like to know why we should use Node, js then due to below-listed advantages it is usually used by the organizations:
Great concurrency is yielded by Node.js
Every feature of Node.js is asynchronous
It is never blocked
It is quite faster
A unified programming language and data type is offered by this

10. Explain various stream of Node.js?
Answer:
In Node.js stream allow users to read data from source and o write data to a destination in a continuous process.
They are just an object and following four types of streams are there in Node.js they are:
To provide read operation
To provide a write operation
To provide both read and write operation
A duplex stream form that can perform computations as per available data.

11. 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 search.nodejs.org
Command-line utility to install packages, do version management and dependency management of Node.js packages. 

12. Explain callback in Node.js?
Answer: A callback function is called at the completion of a given task. This allows other code to be run in the meantime and prevents any blocking. Being an asynchronous platform, Node.js heavily relies on callback. All APIs of Node are written to support callbacks.

13. What is the difference between AngularJS and Node.js?
Answer: Angular.JS is a web application development framework while Node.js is a runtime system.

14. Which Is The First Argument Usually Passed To A Node.Js Callback Handler?
Answer: Node.js core modules follow a standard signature for its callback handlers and usually the first argument is an optional error object. And if there is no error, then the argument defaults to null or undefined. 

15. How To Create A Custom Directive In AngularJS?
Answer: To create a custom directive, we have to first register it with the application object by calling the function. While invoking the method of, we need to give the name of the function implementing the logic for that directive.
For example, in the below code, we have created a copyright directive which returns a copyright text. 

16. What is error-first callback in Node JS?
Answer: In order to check for the proper working of the code, we need to verify error-free execution. In this regard, error-first callbacks are used, that will send error first, followed by related data to the error. 

17. What happens if Node.js technology changes in the future?
Answer: From time to time, we keep adding more questions to this course. Our aim is to keep you always updated with the latest interview questions on Node.js.

18. What is the level of questions in this course?
Answer: This course contains questions that are good for a Fresher to an Architect level. The difficulty level of question varies in the course from a Fresher to an Experienced professional.

19. What is NPM? What is the need of NPM in Node.js?
Answer: NPM stands for Node.js Package Management. It comes with Node.js platform and allows us to install various packages for Node.js. This package manages and supports various commands to install and remove the modules. Here one important note is we require either package.json file or the node_modules folder to install modules locally.
One of the best things about npm is that it locally stores all dependencies. For example, if module X uses module A version 1.0, and module Y uses module A version 1.5, then both X and Y will have their own local copies of module A.
The need for npm package
While I was working on a real node.js application I encountered many instances where I needed to write a few libraries. Recently, I thought these libraries could be useful for others. Afterward, I discovered the npm package.

20. Explain Karma And Jasmine in Node.js?
Answer: Karma is a tool made on top of NodeJS to run JavaScript test cases. This is not a testing framework like Jasmine or Mocha or Chai etc. It only allows us to run JavaScript test cases written using testing frameworks like Jasmine.

Karma runs JavaScript test cases against real browsers through Command Line Interface (CLI) rather than a virtual browser and DOM. Since DOM rendering across browsers varies, for the correctness of the test report it uses real browsers. It can configure what browsers need to be used while running Karma.

21. How does the Node.js server work?
Answer: The require(): Node.js method provides a simple module system. Node.js programs can load individual modules using the require() method. While many modules must be explicitly downloaded, some modules, such as HTTP, called core modules, are bundled with node.js.
The HTTP server is created using the HTTP module’s createServer() method. The createServer() takes a callback function as an argument. This callback function is executed each time the server receives a new request.
The callback function takes two arguments, request, and response. The request object contains information regarding the client’s request, such as the URL, HTTP headers, and much more. Similarly, the response object is used to return data back to the client. 

22. How can you use Node.js MQTT Library?
Answer: MQTT is the most commonly used protocol on the internet of things. There are two key things one has to understand; i.e., the publisher and the subscriber. Let us see some background about publisher and subscriber.
Subscriber is the one which is interested in receiving messages which are published, by the publisher. You can have one or more subscribers registered to receive messages. (Company) Each of these clients gets subscribed to messages via topic or topics.
The publisher is the one who is responsible for publishing the messages. All clients who are subscribed to a specific topic or topics will get notified with the message published by the publisher.
We are building a sample “nodejs” client and server application using MQTT library to demonstrate how we can take advantage of how the MQTT nodejs library subscribes and publishes messages with ease. Node.js is very powerful, simple and easy to use. One can really take advantage of building simple and elegant applications using “nodejs”.

23. How can you Implement Visitor Counter in Node.js?
Answer: We would just like to implement a simple hit count for our web server. For example, we know that in ASP.NET application variables are globally shareable and static in nature, in other words, if a user changes a value then all users will see the changed version.

24. 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.

25. List some of the big advantages of using Node.js?
Answer: Ability to build scalable programs
Increased concurrency
Asynchronous capabilities

26. What are event listeners?
Answer: Events that are emitted by event emitters have to listen in order to continue the asynchronous execution of the threads.
These objects that listens to the emitted events are known as listeners.
Explain file system module of Node
Node fs module provides a simple file system module to perform files related operation. This module comprises of synchronous and asynchronous functions to read/write files. For example, readFile() function is asynchronous function to read file content from specified path and readFileSync() is synchronous function to read files.

27. What is the biggest benefit of this course to me?
Answer: Finally, the biggest benefit of this course is that you will be able to demand a higher salary in your next job interview.
It is good to learn Node.js for theoretical benefits. But if you do not know how to handle interview questions on Node.js, you can not convert your Node.js knowledge into higher salary.

28. What is Cluster Server Object in Node.JS?
Answer: A single instance of Node runs in a single thread. The cluster module allows you to create child processes that all share server ports. When you call server.listen() in a worker, it serializes the argument and passes the request to the master process. If the master process already has a listening server matching the worker’s requirement, then it passes the handle to the server.
If it does not already have a listening server matching that requirement then it will create one and pass the handle to the worker.
Cluster Events
fork
online
listening
disconnect
Fork: the fork event is fired when the master attempts to fork a new child; it receives a worker object.
Online: the online event is fired when the master receives a notification that the child is fully bound; it receives a worker object.
Listening: when the worker performs an action that requires a listen() call such as HTTP server. The event emits two arguments, the first one is a worker object, and the address object contains the address, port, and address type value of the connection.
Disconnect: called whenever a child is disconnected from the cluster; that can happen either through a process or exit event.

29. What is the global installation of dependencies?
Answer: Globally installed packages/dependencies are stored in /npm directory. Such dependencies can be used in CLI (Command Line Interface) function of any node.js but can not be imported using require() in Node application directly. To install a Node project globally use -g flag.

30. Mention the steps by which you can async in Node.js?
Answer:
By following steps you can async Node.js
First-class functions
Function composition
Callback Counters
Event loops

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

32. List out the layers involved in Web App Architecture?
Answer:
Below are the layers used in Web Apps:
Client: Which makes HTTP request to the server. Eg: Browsers.
Server: This layer is used to intercept the requests from the client.
Business: It will have application server utilized by web servers for processing.

33. What is Eventemitter?
Answer: event.EventEmitter is a class which is used to provide a consistent interface for emitting (triggering) and binding callbacks to events. It is used internally in many of the Node core libraries and provides a solid foundation to build event-based classes and applications.

34. Enlist Node.js features?
Answer: Node.js is a highly scalable and single-threaded system that utilizes JavaScript as the scripting language. Rather than using separate threads or processes, it uses event-driven and asynchronous I/O. High output can also be achieved just be single-threaded event loop and by its non-blocking I/O.

35. Explain and list some of the exit codes of Node.js?
Answer:
Exit codes are used to end a specific process in Node.js and are some specific codes. The processes can be any global object as well.
Some of the exit codes are listed below:
Uncaught fatal exception
Unused
Fatal Error
Internal Exception handler Run-time failure
Internal JavaScript Evaluation Failure

36. Explain error-first callback?
Answer: Error-first is used to pass errors and data. if in any case when something went wrong programmers check the first argument and whereas additional arguments are used to pass data. 

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

38. What are the streams in Node.js?
Answer: The Streams are the objects that facilitate you to read data from a source and write data to a destination. There are four types of streams in Node.js:
Readable: This stream is used for reading operations.
Writable: This stream is used for write operations.
Duplex: This stream can be used for both reading and write operations.
Transform: It is a type of duplex stream where the output computes according to input.

39. What does Node.js TTY module contain?
Answer: The Node.js TTY module contains tty.ReadStream and tty.WriteStream classes. In most cases, there is no need to use this module directly. You have to used require (‘tty’) to access this module.

40. What are “streams” in Node.js? Explain the different types of streams present in Node.js?
Answer:
Streams are objects that allow the reading of data from the source and writing of data to the destination as a continuous process.
There are four types of streams.
to facilitate the reading operation
to facilitate the writing operation
to facilitate both read and write operations is a form of Duplex stream that performs computations based on the available input

41. 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.
Good For A Collaborative Environment. It is suitable for environments where multiple people work together. For example, they post their documents, modify them by doing check-out and check-in of these documents.
Node.js supports such situations by creating an event loop for every change made to the document. The “Event loop” feature of Node.js enables it to handle multiple events simultaneously without getting blocked.
Advertisement Servers.
Here again, we have servers that handle thousands of request for downloading advertisements from a central host. And Node.js is an ideal solution to handle such tasks.
Streaming Servers.
Another ideal scenario to use Node.js is for multimedia streaming servers where clients fire request’s towards the server to download different multimedia contents from it.
To summarize, it’s good to use Node.js, when you need high levels of concurrency but less amount of dedicated CPU time.
Last but not least, since Node.js uses JavaScript internally, so it fits best for building client-side applications that also use JavaScript.

42. What Is Chaining Process In Node.Js?
Answer: It’s an approach to connect the output of one stream to the input of another stream, thus creating a chain of multiple stream operations.

43. What Is A Child_process Module In Node.Js?
Answer:
Node.js supports the creation of child processes to help in parallel processing along with the event-driven model.
The Child processes always have three streams , child.stdout, and child.stderr. The stream of the parent process shares the streams of the child process.
Node.js provides a module which supports the following three methods to create a child process. 

44. What are the two types of API functions in Node.js?
Answer:
The two types of API functions in Node.js are:

Asynchronous, non-blocking functions
Synchronous, blocking functions

45. Explain the local installation of dependencies?
Answer: By default, npm will install the dependency in the local mode. Here local mode refers to the package installation in node_modules directory lying in the folder where Node application is present. “require ()” is used to access the locally deployed packages.

46. What Is A Control Flow Function? What Are The Steps Does It Execute?
Answer:
It is a generic piece of code which runs in between several asynchronous function calls is known as control flow function.
It executes the following steps.
Control the order of execution.
Collect data.
Limit concurrency.
Call the next step in the program.

47. Why do we use Node.js and how does Node.js work?
Answer: Node.js is specially designed for building fast, efficient, scalable network applications and uses an event-driven, non-blocking I/O model to maximize efficiency. The callback function is what Node calls a listener function and it is called by the server whenever a new request comes in.

How it works:

The following describes how Node.js works, You use your web browser to make a request for “about.html” on a Node.js web server.
The Node server accepts your request and calls a function to retrieve that file from disk.
While the Node server is waiting for the file to be retrieved, it services the next web request.
When the file is retrieved, there is a callback function inserted into the Node server’s queue.
The Node server executes that function that in this case would render the HTML page and send it back to your browser.
Platforms for Node.js
Runs on OSX, Linux, and Windows.
Clickable installer for Windows and MacOSX.

Note: Browse latest Node JS Interview Questions and Angular training videos. Here you can check Angular JS Online Training details and React Js Training Videos for self learning. Contact +91 988 502 2027 for more information.

Leave a Comment

FLAT 30% OFF

Coupon Code - GET30
SHOP NOW
* Terms & Conditions Apply
close-link