Have a question with NODEJS “CORS Errors”?

I have just worked out a couple of CORS errors (with googling & reading 3 sources) here is what I used (I hope that my spent time will save yours :) )

NodeJS can be configured to use CORS as means of communicating from the front-end. This can be configured in your app.js as middleware for the popular Express package. CORS errors look something like this:


Both servers are running on different ports. Remember that different port consists as a cross domain request. localhost:8080 is a different domain to localhost:9000 (it’s everything before the forward slash). Node running on port 8080Angular running on port 9000You need to include your CORS enabler before your middleware or app.send requests.

You can either include the following code or include an express middleware package to do this for you, such as npm install CORS.

// Enable CORS
app.use(function( req, res, next ) {
res.header("Access-Control-Allow-Origin", req.headers.origin);
res.header("Access-Control-Allow-Headers", "x-requested-with, content-type");
res.header("Access-Control-Allow-Methods", "GET,PUT,POST,DELETE,OPTIONS");
res.header("Access-Control-Allow-Credentials", "true");
res.header("Access-Control-Max-Age", "1000000000");
// intercept OPTIONS method if ('OPTIONS' == req.method) { res.send(200); } else { next(); } });

Setting the domain in the Angular Seed

You may need to set the domain in the Angular seed go to /app/scripts/config.js Change this line:


To this:


Where the IP address can be your domain name.



Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hi there,

This is great! Thank you for sharing this with the community!

I would just add the following reference to the App Platform docs in case anyone is using the App Platform: