Cross Origin Resource Sharing

Gaya's techtips
May 23, 2022

When i developing react and vue frontends when testing with express backend i experienced that there are errors occurring. That error is easily fixed by using a library named cors. This is my study about cors

Cors meaning is cross origin resource sharing. It permits loading resources from other resources. It is the http header mechanism. That resource may be another domain,port,schema also.

When I wanted to make a request from www.domain1.com to www.domain2.com then I wanted cors.

Enable cors in node js server

Install cors package using following command

npm install cors
or
yarn add cors

Write code like this.

const express = require(“express”)
const app = express();
const cors = require(“cors”)
app.use(cors())

Cors technology has both client side and server side components.

--

--