In Express, how can you enable Cross-Origin Resource Sharing (CORS) for your API?

  • app.use(cors())
  • app.enable(cors)
  • app.allow(CORS)
  • app.cors(true)
To enable Cross-Origin Resource Sharing (CORS) in Express, you should use the cors middleware by adding app.use(cors()) to your application. This middleware allows or restricts cross-origin HTTP requests. The other options are not valid ways to enable CORS in Express.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *