Friday, March 29, 2019

How to: enable CORS in express.js (node.js)

Express.js is one of the most popular node.js frameworks for serving website or build APIs.

Steps to use CROS in node.js

1. npm install cors
2. Use the following code
   var express = require('express')
   var cors = require('cors')
   var app = express()

app.use(cors())

app.get('/userList', function (req, res, next) {
  res.json({msg: 'Enabled the CROS'})
})

app.listen(80, function () {
  console.log('Enabled CORS listening on port 80')
}) 

No comments:

Post a Comment