Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Expressjs Error- ReferenceError: cors is not defined

I am creating An ExpressJs Backend when I run this backend I am getting this error.

app.use(cors())
    ^

ReferenceError: cors is not defined
    at Object.<anonymous> (C:\Users\hp\Desktop\Entri\kanba\index.js:5:5)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Module.load (node:internal/modules/cjs/loader:1119:32)
    at Module._load (node:internal/modules/cjs/loader:960:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:23:47

I am sending a get request from postman. I expect response from backend but what I get it an error.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

It seems like you have not installed the middleware called cors.

Run this command in your project’s terminal to install cors

npm install cors

Now you should import the cors package in your application

const cors = require(‘cors’)

For more information, please checkout express cors documentation

Hope this works. Have a good day!

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading