What Is Node - JS? Where Can You Use It?
What Is Node - JS? Where Can You Use It?
Node.js makes building scalable network programs easy. Some of its advantages
include:
• It is generally fast
• It rarely blocks
• Everything is asynchronous
A web server using Node.js typically has a workflow that is quite similar to the
diagram illustrated below. Let’s explore this flow of operations in detail.
• Clients send requests to the webserver to interact with the web application.
Requests can be non-blocking or blocking:
• Deleting data
• Node.js retrieves the incoming requests and adds those to the Event Queue
• The requests are then passed one-by-one through the Event Loop. It
checks if the requests are simple enough not to require any external
resources
A single thread from the Thread Pool is assigned to a single complex request. This
thread is responsible for completing a particular blocking request by accessing
external resources, such as computation, database, file system, etc.
Once the task is carried out completely, the response is sent to the Event Loop that
sends that response back to the client.
A callback function is called after a given task. It 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.
• Improved readability.
• The term I/O is used to describe any program, operation, or device that
transfers data to or from a medium and to or from another medium
• Every transfer is an output from one medium and an input into another. The
medium can be a physical device, network, or files within a system
1. Real-time chats
2. Internet of Things
5. Streaming applications
6. Microservices architecture
Front-end Back-end
NPM stands for Node Package Manager, responsible for managing all the packages
and modules for Node.js.
Node.js has many modules to provide the basic functionality needed for a web
application. Some of them include:
Angular Node.js
MongoDB is the most common database used with Node.js. It is a NoSQL, cross-
platform, document-oriented database that provides high performance, high
availability, and easy scalability.
The “require” command 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.
Now that we have covered some of the important beginner-level Node.js interview
questions let us look at some of the intermediate-level Node.js interview questions.
Node.js Interview Questions and Answers For
Intermediate Level
The distinction between method and product. This is accomplished through the use
of nextTick() and setImmediate(). next Tick() postpones the execution of action until
the next pass around the event loop, or it simply calls the callback function once the
event loop's current execution is complete, whereas setImmediate() executes a
callback on the next cycle of the event loop and returns control to the event loop for
any I/O operations.
• EventEmitter is a class that holds all the objects that can emit events
• Whenever an object from the EventEmitter class throws an event, all
attached functions are called upon synchronously
The package.json file is the heart of a Node.js system. This file holds the metadata
for a particular project. The package.json file is found in the root directory of any
Node application or module
This is what a package.json file looks like immediately after creating a Node.js
project using the command: npm init
You can edit the parameters when you create a Node.js project.
26. How would you use a URL module in Node.js?
Express is a flexible Node.js web application framework that provides a wide set of
features to develop both web and mobile applications
• The request object represents the HTTP request and has properties for the
request query string, parameters, body, HTTP headers, and so on
• The response object represents the HTTP response that an Express app
sends when it receives an HTTP request
29. What are streams in Node.js?
Streams are objects that enable you to read data or write data continuously.
Transform − A type of duplex stream where the output is computed based on input