Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Cannot find module 'cors'

Tags:

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)` 
like image 413
erickimme Avatar asked Dec 08 '17 00:12

erickimme


People also ask

How do I fix node error in CORS?

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.

What is CORS module in node js?

CORS is a node. js package for providing a Connect/Express middleware that can be used to enable CORS with various options.

How do I enable CORS in node js?

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.

Why CORS is used in Node js?

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.


1 Answers

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)

like image 65
Ido.Co Avatar answered Sep 21 '22 07:09

Ido.Co