I keep getting this error message below: I tried to find other stackoverflow post and articles but couldn't really sovle it. do any of you guys know what the problem is it?
`kimeric@pal-nat186-87-17 ~/Desktop/cs390/Assignment9/backEnd master ✚ ● ? node server9.js module.js:472 throw err; ^ Error: Cannot find module 'cors' at Function.Module._resolveFilename (module.js:470:15) at Function.Module._load (module.js:418:25) at Module.require (module.js:498:17) at require (internal/module.js:20:19) at Object.<anonymous> (/Users/kimeric/Desktop/cs390/Assignment9/backEnd/server9.js:11:12) at Module._compile (module.js:571:32) at Object.Module._extensions..js (module.js:580:10) at Module.load (module.js:488:32) at tryModuleLoad (module.js:447:12) at Function.Module._load (module.js:439:3)`
To solve this error, we need to add the CORS header to the server and give https://www.section.io access to the server response. Include the following in your index. js file. const cors = require('cors'); app.
CORS is a node. js package for providing a Connect/Express middleware that can be used to enable CORS with various options.
Enable All CORS Requests If you want to enable CORS for all the request you can simply use the cors middleware before configuring your routes: const express = require('express'); const cors = require('cors'); const app = express(); app.
CORS stands for Cross-Origin Resource Sharing . It allows us to relax the security applied to an API. This is done by bypassing the Access-Control-Allow-Origin headers, which specify which origins can access the API.
Run npm install cors --save
from the command line in the main project directory to install it and add it to your package.json
It is possible that the cors module was separated from the main express package a long time ago, and the code you are using was written before that. (Or never was a part of it, to begin with)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With