Professional Documents
Culture Documents
Ans: 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.
Ans: 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. What is the package.json file?
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.
Ans:
Pros:
• If your application does not have any CPU intensive computation, you can build it in
Javascript top to bottom, even down to the database level if you use JSON storage
object DB like MongoDB.
• Crawlers receive a full-rendered HTML response, which is far more SEO friendly rather
than a single page application or a websockets app run on top of Node.js.
Cons:
Ans: To process and handle external events and to convert them into callback invocations an
event loop is used. So, at I/O calls, node.js can switch from one request to another.
Answer: Node.js is single-threaded. Still, it can perform non-blocking operations. This is possible
because of the event loop. The event loop allows Node.js to perform non-block operations by
assigning operations to the OS wherever and whenever possible.
Ans: Node.js solves this problem by putting the event-based model at its core, using an event
loop instead of threads.
8. What is a promise?
Ans: A promise in Node.js is a value returned by an asynchronous function. It indicates that a
process carried out by the asynchronous function is completed.
9. What is a promise?
Ans: npm is that the default package manager for the JavaScript runtime atmosphere Node.js. It
consists of a statement consumer, additionally referred to as npm, and internet information of
public and paid-for personal packages, referred to as the npm written record. The written record
is accessed via the consumer, and also the accessible packages will be browsed and searched via
the npm website. The package manager and also the written record area unit managed by npm,
Inc
Ans: Node.js is a runtime environment for applications written in JavaScript. It’s not a full-
fledged scripting language like Python. However, Node.js uses JavaScript as its scripting
language. Various tutorials show how to use the scripting capabilities of JavaScript when
developing a Node.js application.
13. How to extract the filename from a file path in Node.js?
Ans: Node.js offers a method called “path.basename()”. Developers can use this to extract the
filename from a Node JS file path.
Ans: All Node.js library APIs support asynchronous processing. Therefore, all of them have non-
blocking processing.
Node.js-based servers don’t wait for an API to return data. It calls an API and allows it to work.
Meanwhile, it moves to the next API. Node.js has a notification mechanism, that responds to the
server for the earlier API call.
Ans: A URL module helps to parse URLs and splits the web address into host, pathname, search,
query, etc.