Abstract
As you said, it enables CORS (cross-origin resource sharing). In order for your server to be accessible by other origins (domains).
What it really does
Calling use(cors()) will enable the express server to respond to preflight requests.
A preflight request is basically an OPTION request sent to the server before the actual request is sent, in order to ask which origin and which request options the server accepts.
So CORS is basically a set of headers sent by the server to the browser.
Calling cors() without any additional information will set the following defaults:
{
"origin": "*",
"methods": "GET,HEAD,PUT,PATCH,POST,DELETE",
"preflightContinue": false,
"optionsSuccessStatus": 204
}
These are translated into these headers:
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET,HEAD,PUT,PATCH,POST,DELETE
Status Code: 204
It is basically making your server accessible to any domain that requests a resource from your server via a browser.
You can check all the Express.js cors configurations at cors (GitHub).
You can also read more about browser cors at Cross-Origin Resource Sharing (CORS) (MDN).