Question: Trying to deal with CORS set up a simple Node / Express server like so:

```
const express = require('express');
var cors = require('cors');
const app = express();

const port = process.env.PORT || 3000;

app.use(cors());

app.use(express.static('public'));

app.listen(port, () => {
  console.log('Server active on port: ', port);
});

```

Using this cors lib: <https://www.npmjs.com/package/cors>

The rest is a simple app using JQuery ajax to fetch some data... Works with the CORS chrome extension enabled but can't figure out how to set up a simple server so that I do not have to use the chrome extension...

Answer: 
You may try setting the options to be passed to your `cors` package, like this,

```
const corsOptions = {
    origin: process.env.CORS_ALLOW_ORIGIN || '*',
    methods: ['GET', 'PUT', 'POST', 'DELETE', 'OPTIONS'],
    allowedHeaders: ['Content-Type', 'Authorization']
};

app.use(cors(corsOptions)); 

```

Hope this helps.
You can use a cors middleware like this

```
 const corsMiddleware = (req: Request, res: Response, next: NextFunction) => {
  logger.debug(req.method + " at " + req.url);
  res.setHeader("Access-Control-Allow-Origin", "*"); // you can optionally replace * with your server address
  res.setHeader("Access-Control-Allow-Credentials", "true");
  res.setHeader(
    "Access-Control-Allow-Methods",
    "POST, GET, PUT, DELETE, OPTIONS"
  );
  res.setHeader(
    "Access-Control-Allow-Headers",
    "Origin, X-Requested-With, Content-Type, Accept, Authorization"
  );

  next();
};

```

To use this middleware for all kinds of requests, use 

```
app.all("*", corsMiddleware);

```

This will add these headers in all the requests.