You are on page 1of 4

1. What is Node.js? Where can you use it?

Ans: Node.js is an open-source, cross-platform JavaScript runtime environment and library to


run web applications outside the client’s browser. It is used to create server-side web
applications.

Node.js is perfect for data-intensive applications as it uses an asynchronous, event-driven model.


You can use 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 callback in Node.js.

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.

3. Which database is more popularly used with Node.js?

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.

4. Where Node.js can be used?

Ans: Node.js can be used to develop:

• Real-Time Web Applications


• Network Applications
• Distributed Systems
• General Purpose Applications

5. What are the pros and cons of Node.js?

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:

• Any intensive CPU computation will block node.js responsiveness, so a threaded


platform is a better approach.
• Using relational database with Node.js is considered less favourable.

6. What is an event loop in Node.js?

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.

7. How Node.js overcomes the problem of blocking of I/O operations?

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

10. Can you access DOM in the node?

Ans: No, you cannot access DOM(document object model) in node.

11. What is npm in node js?

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

• It works as a web repository for node.js packages/modules which can be found on


https://www.npmjs.com/.
• It works as a Command-line utility to install packages bundles.

12. Does Node.js support scripting?

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.

14. How do the asynchronous and non-blocking APIs in Node.js work?

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.

15. How does a URL module work in Node.js?

Ans: A URL module helps to parse URLs and splits the web address into host, pathname, search,
query, etc.

You might also like