NodeJS Interview Question
NodeJS Interview Question
js Interview Questions
1) What is Node.js?
Node.js is Server-side scripting which is used to build scalable programs. It is a web
application framework built on Google Chrome's JavaScript Engine. It runs within the
Node.js runtime on Mac OS, Windows, and Linux with no changes. This runtime
facilitates you to execute a JavaScript code on any machine outside a browser.
o Node.js is asynchronous and event-driven. All API?s of Node.js library are non-blocking,
and its server doesn't wait for an API to return data. It moves to the next API after calling
it, and a notification mechanism of Events of Node.js responds to the server from the
previous API call.
o Node.js is very fast because it builds on Google Chrome?s V8 JavaScript engine. Its
library is very fast in code execution.
o Node.js is single threaded but highly scalable.
o Node.js provides a facility of no buffering. Its application never buffers any data. It
outputs the data in chunks.
o Client Layer: The Client layer contains web browsers, mobile browsers or applications
which can make an HTTP request to the web server.
o Server Layer: The Server layer contains the Web server which can intercept the request
made by clients and pass them the response.
o Business Layer: The business layer contains application server which is utilized by the
web server to do required processing. This layer interacts with the data layer via
database or some external programs.
o Data Layer: The Data layer contains databases or any source of data.
7) What do you understand by the term I/O?
The term I/O stands for input and output. It is used to access anything outside of your
application. The I/O describes any program, operation, or device that transfers data to
or from a medium or another medium. This medium can be a physical device, network,
or files within a system.
I/O is loaded into the machine memory to run the program once the application starts.
The following table specifies the crucial differences between JavaScript and Node.js:
Comparison JavaScript Node.js
features
Utility JavaScript is used for any client-side Node.js is used for accessing or
activity for a web application. performing any non-blocking
operation of any operating system.
Running Engine The running engine for JavaScript is The running engine for Node.js is
Spider monkey (Firefox), JavaScript Core V8 (Google Chrome).
(Safari), V8 (Google Chrome), etc.
Browser JavaScript can only be run in browsers. The Node.js code can be run
compatibility outside the browser.
Platform JavaScript is basically used on the client- Node.js is mostly used on the
dependency side and is used in frontend server-side and is used in server-
development. side development.
o According to the above diagram, the clients send requests to the webserver to interact
with the web application. These requests can be non-blocking or blocking and used for
querying the data, deleting data, or updating the data.
o js receives the incoming requests and adds those to the Event Queue.
o After this step, the requests are passed one by one through the Event Loop. It checks if
the requests are simple enough not to require any external resources.
o The event loop then processes the simple requests (non-blocking operations), such as
I/O Polling, and returns the responses to the corresponding clients.
o 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.
o Once the task is completed, the response is sent to the Event Loop that sends that
response back to the client.
12) How can you manage the packages in your
Node.js project?
We can manage the packages in our Node.js project by using several package installers
and their configuration file accordingly. Most of them use npm or yarn. The npm and
yarn both provide almost all libraries of JavaScript with extended features of controlling
environment-specific configurations. We can use package.json and package-lock.json to
maintain versions of libs being installed in a project. So, there is no issue in porting that
app to a different environment.
o Internet of Things
o Real-time collaboration tools
o Real-time chats
o Complex SPAs (Single-Page Applications)
o Streaming applications
o Microservices architecture etc.
As the name specifies, the front-end As the name specifies, the back-end
development is the part of a web development consists of everything that
application where users can see and happens behind the scenes and users cannot see
interact. and interact with.
HTML, CSS, Bootstrap, jQuery, JavaScript, Java, PHP, Python, C++, Node.js, etc., are the
AngularJS, and React.js are essential technologies required for back-end
front-end development technologies. development.
Node.js has several modules which are used to provide the basic functionality needed
for a web application. Following is a list of some of them:
Core Description
Modules
HTTP: The HTTP module includes classes, methods, and events to create a Node.js HTTP server.
util: The util module includes utility functions required in the application and is very useful fo
developers.
url: The url module is used to include the methods for URL parsing.
fs: The fs module includes events, classes, and methods to handle the file I/O operations.
stream: The stream module is used to include the methods to handle streaming data.
query string: The query string module is used to include the methods to work with a query string.
zlib: The zlib module is used to include the methods to compress or decompress the files used i
an application.
23) What are buffers in Node.js?
In general, a buffer is a temporary memory mainly used by the stream to hold on to
some data until it is consumed. Buffers are used to represent a fixed-size chunk of
memory allocated outside of the V8 JavaScript engine. It can't be resized. It is like an
array of integers, which each represents a byte of data. It is implemented by the Node. js
Buffer class. Buffers also support legacy encodings like ASCII, utf-8, etc.
Syntax:
node debug [script.js | -e "script" | <host>:<port>]
$ node
> 100 + 200
300
> 100 + ( 200 * 300 ) - 400
59700
>
C:\Nodejs_WorkSpace>node
> var x = 10
undefined
> var y = 20
undefined
>x+y
30
> var sum = _
undefined
> console.log(sum)
30
undefined
>
o JSLint
o JSHint
o ESLint
o JSCS
Syntax:
punycode = require('punycode');
Syntax:
1. var tty = require('tty');
Angular Node.js
Angular is a structural front-end development Node.js is a cross-platform, run-time,
framework for developing dynamic web apps. server-side environment for applications
written in JavaScript language.
Angular is used for building single-page, client- Node.js is used for building fast and
side web applications. scalable, client-side, and server-side
networking applications.
Angular is easy to use. The developers need to Node.js is slightly complicated to use. Here,
add the Angular file to use it in their the developers need to install Node.js on
applications. their computer system.
Angular split a web application into MVC Node.js generates database queries and
components. Here, the models and views are uses the event-driven nature of JavaScript
much simpler than what is found in other to support non-blocking operations,
JavaScript client-side frameworks. making the platform efficient.
Angular is ideal for creating highly active and Node.js is the best for developing small-
interactive web apps. size projects.
Example: