DEV Community

Dushyant Pathak
Dushyant Pathak

Posted on

CORS error hack

Cross-Origin Resource Sharing (CORS) is a mechanism that uses additional HTTP headers to tell browsers to give a web application running at one origin, access to selected resources from a different origin.

A web application executes a cross-origin HTTP request when it requests a resource that has a different origin (domain, protocol, or port) from its own.

An example of a cross-origin request: the front-end JavaScript code served from uses XMLHttpRequest to make a request for

More details on CORS can be found here.

Most noobs, who are starting with Back-End development, will often see this error.


The first step would be to use the CORS package, when working with NPM.

npm i cors

//In index.js file,
var cors = require('cors');
Enter fullscreen mode Exit fullscreen mode

Some deployments may still cause the CORS error in some cases, wherein this particular Chrome extension comes handy.

CORS Extension

You just have to Enable and save, and it should solve the CORS error for you.

However, do note that some sites, usually third party API services, such as Newsapi restrict only localhost sites to be able to access their free plan APIs, and will block access requests from deployed websites.

Cheers! Have a CORS-Free day!

Discussion (1)

Some comments have been hidden by the post's author - find out more