searching the web…
const express = require('express');
const cors = require('cors');
const app = express();
app.use(cors({
origin: 'http://localhost:3000',
methods: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH'],
allowedHeaders: ['Content-Type', 'Authorization'],
credentials: true
}));
app.listen(5000, () => {
console.log('Server running on port 5000');
});Install cors package and use middleware to set CORS headers. Specify your frontend origin instead of wildcard for production; preflight requests are handled automatically.