Error: Cannot find module 'cors'

You can simply open the package.json file in any text editor and add cors under dependencies like this: "cors": "2.8.5"

Since the latest version of cors is 2.8.5


Try running npm link cors and then run npm install


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)


Need to install cors library. Use terminal and run "npm install cors" then use below in server.js file:

var express = require('express')
var cors = require('cors')
var app = express()
app.use(cors())

Or, refer link: https://www.npmjs.com/package/cors

Thanks,

Tags:

Cors

Node.Js