Categories
JavaScript Answers

How to fix CORS error :Request header field Authorization is not allowed by Access-Control-Allow-Headers in preflight response with Node?

Spread the love

To fix CORS error :Request header field Authorization is not allowed by Access-Control-Allow-Headers in preflight response with Node, we use the cors package.

To use it, we write

const express = require("express");
const cors = require("cors");
const app = express();
app.use(cors());
app.options("*", cors());

to call app.use with the middleware returned by cors to enable CORS in our Express app.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published.