Question-21. What is an Event Loop in Node.js?
Answer- 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.
Question-22. Differentiate between process.nextTick() and setImmediate()?
Answer- The distinction between method and product. This is accomplished through the use of nextTick() and setImmediate(). next Tick() postpones the execution of action until the next pass around the event loop, or it simply calls the callback function once the event loop’s current execution is complete, whereas setImmediate() executes a callback on the next cycle of the event loop and returns control to the event loop for any I/O operations.
Question-23. What is an EventEmitter in Node.js?
- EventEmitter is a class that holds all the objects that can emit events
- Whenever an object from the EventEmitter class throws an event, all attached functions are called upon synchronously
Question-24. What are the two types of API functions in Node.js?
Answer- The two types of API functions in Node.js are:
- Asynchronous, non-blocking functions
- Synchronous, blocking functions
Question-25. What is the package.json file?
Answer- 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.
Question-26. How would you use a URL module in Node.js?
Answer- The URL module in Node.js provides various utilities for URL resolution and parsing. It is a built-in module that helps split up the web address into a readable format.
Question-27. What is the Express.js package?
Answer- Express is a flexible Node.js web application framework that provides a wide set of features to develop both web and mobile applications
Question-28. How do you create a simple Express.js application?
- The request object represents the HTTP request and has properties for the request query string, parameters, body, HTTP headers, and so on
- The response object represents the HTTP response that an Express app sends when it receives an HTTP request
Question-29. What are streams in Node.js?
Answer- Streams are objects that enable you to read data or write data continuously.
There are four types of streams:
Readable – Used for reading operations
Writable − Used for write operations
Duplex − Can be used for both reading and write operations
Transform − A type of duplex stream where the output is computed based on input