Describe how cross-origin resource sharing (CORS) is handled in Node.js.
Instruction: Explain the concept of CORS and how to implement CORS support in a Node.js application.
Context: This question tests the candidate's knowledge of web security principles, specifically CORS, and their ability to configure a Node.js application to safely interact with resources from different origins.
Updated
Official answer available
Read the opening below, then unlock the full answer and practical guidance.
CORS is a browser-enforced policy controlling whether frontend JavaScript can read a cross-origin response. The server communicates the policy through response headers. CORS is not authentication, authorization or a general mechanism for stopping requests from reaching a server; non-browser clients do not enforce it.
This complete Express 5/CommonJS example allows one frontend origin to read a public GET endpoint:...