15 Interview Questions About NODE
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.