0% found this document useful (0 votes)
2 views

Advanced NodeJS Questions Full (1)

The document contains 50 advanced questions and answers about Node.js, covering topics such as its runtime environment, event loop, asynchronous programming, middleware, streams, and error handling. It also discusses various modules, frameworks, and best practices for building secure and efficient applications. Key concepts include Express.js, JWT tokens, microservices, and deployment strategies.

Uploaded by

sujeetnangare
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)
2 views

Advanced NodeJS Questions Full (1)

The document contains 50 advanced questions and answers about Node.js, covering topics such as its runtime environment, event loop, asynchronous programming, middleware, streams, and error handling. It also discusses various modules, frameworks, and best practices for building secure and efficient applications. Key concepts include Express.js, JWT tokens, microservices, and deployment strategies.

Uploaded by

sujeetnangare
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/ 5

50 Advanced Node.

js Questions with Detailed Answers

1. What is Node.js?
Node.js is a runtime environment that allows executing JavaScript code outside the browser, built on
Chrome's V8 engine.

2. What is the event loop in Node.js?


The event loop is a mechanism that handles asynchronous operations in Node.js, allowing it to be
non-blocking.

3. What is the difference between synchronous and asynchronous programming in Node.js?


Synchronous code executes sequentially, blocking execution, while asynchronous code executes
non-blockingly using callbacks, promises, or async/await.

4. What are streams in Node.js?


Streams are objects that allow reading or writing data in chunks, improving performance for large
files and real-time applications.

5. What is middleware in Express.js?


Middleware functions execute in the request-response cycle and can modify requests, responses, or
terminate the request.

6. What are the different types of streams in Node.js?


Readable, Writable, Duplex, and Transform streams enable efficient data processing.

7. What is the role of the package.json file?


package.json manages project dependencies, scripts, and metadata about a Node.js application.

8. What is clustering in Node.js?


Clustering enables creating multiple worker processes to utilize multi-core CPUs for better
performance.

9. How do you handle exceptions in Node.js?


Using try-catch for synchronous errors, promises with .catch, and process.on('uncaughtException')
for global error handling.

10. What is process.nextTick()?


process.nextTick() defers execution of a function until the next event loop iteration, prioritizing
execution over I/O tasks.

11. What is the difference between process.nextTick() and setImmediate()?


process.nextTick() executes callbacks before I/O tasks, while setImmediate() executes them after
I/O tasks.

12. What is the purpose of the buffer module in Node.js?


The buffer module handles binary data efficiently, useful for handling file I/O and networking.

13. What is the difference between require() and import?


require() is used in CommonJS modules, while import is used in ES modules (ESM).

14. How does Node.js handle child processes?


Using child_process module, Node.js can spawn, fork, or execute external processes
asynchronously.

15. What are worker threads in Node.js?


Worker threads allow executing CPU-intensive tasks in parallel, avoiding the event loop blocking.

16. What is the difference between fork() and spawn() in Node.js?


fork() creates a new process with inter-process communication (IPC), while spawn() launches a new
process without IPC.

17. How does async/await work in Node.js?


async/await simplifies asynchronous programming by allowing synchronous-style code execution
with promises.

18. What is the difference between global and process objects in Node.js?
global provides global variables, while process gives access to runtime information like environment
variables.

19. What is the role of the crypto module in Node.js?


The crypto module provides cryptographic functions like hashing, encryption, and signing data.

20. What is the use of the fs module?


The fs module enables file system operations such as reading, writing, and deleting files.

21. How does Node.js handle HTTP requests?


Using the http module, Node.js can create web servers and handle incoming HTTP requests.

22. What is the difference between HTTP and WebSockets?


HTTP is stateless and request-response-based, while WebSockets provide full-duplex
communication.

23. What are JWT tokens and how are they used in Node.js?
JWT tokens are used for authentication, allowing secure transmission of user identity between client
and server.

24. What is Express.js and why is it popular?


Express.js is a minimalist web framework for Node.js, simplifying request handling and routing.

25. How does middleware work in Express.js?


Middleware functions process requests before reaching route handlers, used for authentication,
logging, etc.

26. What is a CORS policy and how do you handle it in Node.js?


CORS (Cross-Origin Resource Sharing) allows controlled access to resources from different
domains, handled using the cors middleware.

27. How does Node.js handle database operations?


Node.js connects to databases using libraries like Sequelize (for SQL) or Mongoose (for MongoDB).

28. What is connection pooling in databases?


Connection pooling maintains a set of database connections for efficient reuse, reducing latency.

29. What is an ORM and which ORMs are used in Node.js?


ORM (Object-Relational Mapping) simplifies database operations. Examples include Sequelize and
TypeORM.

30. How does authentication work in Node.js?


Authentication can be implemented using JWT, OAuth, session-based authentication, or third-party
services like Passport.js.

31. What is rate limiting and why is it important?


Rate limiting restricts API request frequency to prevent abuse and ensure server stability.

32. What is the purpose of Helmet.js?


Helmet.js secures Express apps by setting various HTTP headers to prevent attacks.

33. What is an event emitter in Node.js?


The EventEmitter class allows implementing the observer pattern by registering and triggering
events.

34. What is the difference between synchronous and asynchronous file operations?
Synchronous file operations block execution, while asynchronous operations allow non-blocking I/O.

35. How does error handling work in Express.js?


Error handling in Express.js is done using middleware with four parameters: (err, req, res, next).
36. How do you deploy a Node.js application?
Node.js apps can be deployed using services like AWS, Heroku, DigitalOcean, or Docker.

37. What is PM2 and how does it help in Node.js applications?


PM2 is a process manager for Node.js that provides load balancing, monitoring, and automatic
restarts.

38. What is Nodemon?


Nodemon automatically restarts a Node.js application when file changes are detected, improving
development workflow.

39. What is an API gateway?


An API gateway acts as an entry point for multiple services, handling authentication, load balancing,
and request routing.

40. What is GraphQL and how does it differ from REST?


GraphQL is a query language for APIs that allows fetching specific data, unlike REST, which returns
fixed responses.

41. How do you handle file uploads in Node.js?


Using multer or formidable middleware, Node.js can process multipart form data for file uploads.

42. What is a WebSocket and how is it implemented in Node.js?


WebSockets enable real-time communication, implemented using the ws library in Node.js.

43. What is an HTTP/2 server in Node.js?


HTTP/2 improves web performance with multiplexing, implemented using the http2 module.

44. How do you handle background jobs in Node.js?


Background jobs can be managed using libraries like Bull (Redis-based job queue) or Agenda
(MongoDB-based).

45. What are microservices and how are they implemented in Node.js?
Microservices architecture breaks applications into small services, implemented using frameworks
like Nest.js or Express.js.

46. What is a message queue in Node.js?


Message queues like RabbitMQ or Kafka handle asynchronous processing and inter-service
communication.

47. How does logging work in Node.js?


Logging can be implemented using libraries like Winston or Morgan for structured logging and
debugging.
48. What is Docker and how is it used with Node.js?
Docker containerizes applications, ensuring consistency across environments and simplifying
deployments.

49. How do you implement role-based access control (RBAC) in Node.js?


RBAC restricts actions based on user roles, implemented using middleware that verifies user
permissions.

50. What are some best practices for securing a Node.js application?
Best practices include validating input, securing dependencies, using HTTPS, enforcing
authentication, and limiting request rates.

You might also like