[go: up one dir, main page]

0% found this document useful (0 votes)
12 views2 pages

Complete_NodeJS_Questions_And_Answers

Node.js is a JavaScript runtime that enables server-side execution and is optimized for I/O-heavy applications. It utilizes an event-driven, non-blocking I/O model and includes features like the event loop, Promise handling, and the cluster module for performance. Best practices for security include using a .env file for sensitive information management.

Uploaded by

R.K Tiwari
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
0% found this document useful (0 votes)
12 views2 pages

Complete_NodeJS_Questions_And_Answers

Node.js is a JavaScript runtime that enables server-side execution and is optimized for I/O-heavy applications. It utilizes an event-driven, non-blocking I/O model and includes features like the event loop, Promise handling, and the cluster module for performance. Best practices for security include using a .env file for sensitive information management.

Uploaded by

R.K Tiwari
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/ 2

Node.

js Interview Questions and Answers

1. What is Node.js?

Node.js is a JavaScript runtime built on Chrome's V8 engine. It allows you to run JavaScript on the
server-side. Node.js is designed for building scalable network applications using an event-driven,
non-blocking I/O model. It excels at handling many simultaneous connections efficiently.

2. When is Node.js preferable?

Node.js is ideal for:

- I/O-heavy applications (e.g., real-time chat, REST APIs)

- Microservices

- Real-time collaboration tools (e.g., Google Docs)

- Streaming apps

It's not ideal for CPU-heavy tasks due to its single-threaded nature.

3. What is the Event Loop?

The event loop is the core of Node.js's asynchronous architecture. It manages the execution of
multiple tasks without blocking the main thread. The event loop handles callbacks, promises, timers,
and I/O operations in a loop that picks tasks from the event queue and executes them when ready.

4. How can we do multiple API calls with Promise.all and Promise.allSettled?

Promise.all runs multiple promises in parallel and fails fast if one rejects. Use it when all must
succeed.

Promise.allSettled waits for all to complete regardless of success/failure, returning their status and
value or reason. Use it when you can tolerate some failures.

5. What is a REST API?

A REST API is a web API that follows the principles of REST. It uses HTTP methods (GET, POST,
PUT, DELETE) to interact with resources identified by URLs. REST APIs are stateless, scalable,
and often return data in JSON format.
6. What is synchronous and asynchronous behavior in Node.js?

Synchronous operations block execution until they finish. Asynchronous operations (Node.js default)
use callbacks, promises, or async/await to allow other tasks to run while waiting. This makes
Node.js efficient for I/O-heavy operations.

7. What is cluster in Node.js?

The cluster module allows Node.js to create child processes (workers) that share the same server
port. It enables multi-core CPU usage and improves performance by running multiple instances of
the app in parallel.

8. How is Node.js non-blocking?

Node.js is non-blocking due to its event-driven architecture. It uses an event loop and async APIs to
handle tasks without waiting. It immediately moves on to the next task and executes the result via
callback/promise when ready.

9. How do we protect our server-related sensitive information using process.env?

Use a .env file to store secrets and access them via process.env. Install the dotenv package to load
them. Add .env to .gitignore to prevent committing secrets. This keeps your credentials secure and
configurable without hardcoding.

You might also like