install cors
npm install cors
express js cors
var express = require('express')
var cors = require('cors') //use this
var app = express()
app.use(cors()) //and this
app.get('/user/:id', function (req, res, next) {
res.json({user: 'CORS enabled'})
})
app.listen(5000, function () {
console.log('CORS-enabled web server listening on port 5000')
})
Install Cors
$ npm i express cors
cors package install npm
var express = require('express')var cors = require('cors')var app = express() app.get('/products/:id', cors(), function (req, res, next) { res.json({msg: 'This is CORS-enabled for a Single Route'})}) app.listen(80, function () { console.log('CORS-enabled web server listening on port 80')})
cors package install npm
var express = require('express')var cors = require('cors')var app = express() app.use(cors()) app.get('/products/:id', function (req, res, next) { res.json({msg: 'This is CORS-enabled for all origins!'})}) app.listen(80, function () { console.log('CORS-enabled web server listening on port 80')})
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us