Use cors in Your Express Application

If you are using Express, you can set up CORS by including the cors middleware in your application. Here’s a basic example:

const express = require('express');
const cors = require('cors');

const app = express();

// Enable CORS for all origins
app.use(cors());

// Your routes here
app.get('/', (req, res) => {
  res.send('Hello, world!');
});

const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
  console.log(`Server running on port ${PORT}`);
});

Comments

Leave a Reply

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