Access to XMLHttpRequest at ‘…’ from origin ‘localhost:3000’ has been blocked by CORS policy

if you are building your rest api in nodejs. Follow the folowing simple steps

Stop the Node.js server.

npm install cors --save

Add following lines to your server.js or index.js

var cors = require('cors')

app.use(cors()) // Use this after the variable declaration

Now try to make your api call on the client side and it should work

Leave a Comment