[go: up one dir, main page]

100% found this document useful (1 vote)
58 views3 pages

15 Interview Questions About NODE

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
58 views3 pages

15 Interview Questions About NODE

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

15 interview questions about NODE.

JS
1. What is Node.js? Where can we use it?
Ans: Node.js is an open-source, cross-platform, back-end JavaScript runtime environment that
runs on the V8 engine. It is used to develop APIs on the server side. NoSQL and SQL databases
can be used. This language has a large number of libraries. We can use it for developing: Real-
time web applications, Network applications, General-purpose applications, Single-page
applications, and Distributed systems.
2. How does Node.js work?
Ans: NodeJs executes on v8 environment which act as virtual machine. This virtual machine
utilizes JavaScript as its scripting language and generates output via non-blocking I/O and
single threaded event loop.
3. Why is Node.js Single-threaded?
Ans: Nodejs is single-threaded as JavaScript executed in single thread with event loop. Event
mechanism helps the server to respond in an asynchronous way and make server highly
scalable.
4. If Node.js is single-threaded, then how does it handle concurrency?
Ans: The Node JS Processing paradigm is heavily influenced by the JavaScript Event-based
model and the JavaScript callback system. As a result, Node.js can easily manage more
concurrent client requests. The event loop is the processing model's beating heart in Node.js.
5. What is NPM?
Ans: NPM stands for Node Package Manager, responsible for managing all the packages and
modules for Node.js.
Node Package Manager provides two main functionalities:
i.Provides online repositories for node.js packages/modules, which are searchable on
search.nodejs.org
ii.Provides command-line utility to install Node.js packages and also manages Node.js
versions and dependencies
6. What are the common error codes in an API?
Ans:
• 404 Not Found. It means the server could not find the requested resource.
• 401 Unauthorized. This status code means you haven’t yet authenticated against the
API.
• 403 Forbidden. It means that the client who is requesting is known to the server but
does not have access.
• 400 Bad Request. It occurs due to syntax errors.
• 429 Too Many Requests. It happens when a user sends too many requests in a period of
time.
• 500 Internal Server Error. The server encountered an unexpected error.
• 503 Service Unavailable. The server is not ready to handle the request.
7. If Nodejs is single-threaded, how does it handle multiple asynchronous processes?
Ans: Although Nodejs is single-threaded, it works on an event loop model. The event loop is a
never-ending loop that keeps on consuming the upcoming processes. In the event loop, there
is a queue that manages upcoming async processes and there is a listener at the end. The
event loop consists of different types of phases which handle async functions passing through
it. Using event loop, the main thread assigns different threads to different async processes
which help in the execution of each process.
8. What does event-driven programming mean?
Ans: An event-driven programming approach uses events to trigger various functions. An
event can be anything, such as typing a key or clicking a mouse button. A call-back function is
already registered with the element executes whenever an event is triggered.

9. What is an Event Loop in Node.js?


Ans: Event loops handle asynchronous callbacks in Node.js. It is the foundation of the non-
blocking input/output in Node.js, making it one of the most important environmental features.

10. How does Event Loop work in Node.js?


Ans: The Event loop manages each asynchronous callback. As Node.js utilizes a single thread
and is event-driven, the developer can include specific listeners to an event — when the said
event goes off, the listener will execute the callback we provided. Node.js executes one
operation and doesn’t stop to wait for the output; instead, it keeps on executing other code
parts. After an operation is executed, the output is received and the callback function is run —
in this case, each of the callback functions is queued in this Event Loop and run consecutively.

11. What is the package.json file?


Ans: 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.
12. What is REPL in Node.js?
Ans:
• Read: As the name indicates, user input is read and converted into JavaScript data
structure and then stored in memory.
• Eval: Receives and evaluates data structure.
• Print: Final output is printed
• Loop: Command is looped until CTRL + C is pressed twice.

13. Explain the concept of middleware in Node.js.


Ans: Middleware comes in between your request and business logic. It is mainly used to
capture logs and enable rate limit, routing, authentication, basically whatever that is not a
part of business logic. There are third-party middleware also such as body-parser and you
can write your own middleware for a specific use case.
14. What are the different types of HTTP requests?
Ans: HTTP defines a set of request methods used to perform desired actions. The request
methods include:
GET: Used to retrieve the data
POST: Generally used to make a change in state or reactions on the server
HEAD: Similar to the GET method, but asks for the response without the response body
DELETE: Used to delete the predetermined resource

15. What does it mean "non-blocking" and "blocking" in NodeJs?


Ans: Non-blocking: Non-blocking code are those which doesn't wait for previous assign task to
complete. Non-blocking code means that the IO is not blocking. Non-blocking code do not
execute in sequence.
Blocking: Blocking code refers when an application wait for some I/O operation in order to
complete its execution. It wait for previous assign task to complete first when multiple task
assign to server.

You might also like