Ques 26. Explain the purpose of the 'dotenv' module in Node.js.
The 'dotenv' module is used to load environment variables from a '.env' file into 'process.env'. It is commonly used in Node.js applications to manage configuration variables.
Example:
require('dotenv').config();
Is it helpful?
Add CommentView Comments
Ques 27. What is the role of the 'WebSocket' protocol in Node.js?
WebSocket is a communication protocol that provides full-duplex communication channels over a single, long-lived connection. In Node.js, the 'ws' library is commonly used to implement WebSocket servers and clients.
Ques 28. Explain the concept of 'middleware chaining' in Express.js.
Middleware chaining in Express.js is the process of sequentially applying multiple middleware functions to a request. Each middleware function can modify the request and response objects or terminate the request-response cycle.
Ques 29. What is the purpose of the 'pm2' module in Node.js?
'pm2' is a process manager for Node.js applications. It allows you to run, monitor, and manage Node.js processes, enabling features like automatic restarts, clustering, and log management.
Example:
pm2 start app.js
Is it helpful?
Add CommentView Comments
Ques 30. Explain the purpose of the 'CORS' middleware in Express.js.
CORS (Cross-Origin Resource Sharing) middleware in Express.js is used to enable or restrict cross-origin HTTP requests. It adds the necessary headers to allow or deny requests from different origins.