Basic Node and Express - Use the .env File will not validate

Tell us what’s happening:

Validation does not seem to be working. I have visited the /json endpoint and changed the conditions (associated with the MESSAGE_STYLE=uppercase variable in the .env file), and confirmed that the message changes (the way it should) in the browser. However, when I submit the solution, it fails. There are no errors in the console, nor are there any errors in the logs of the glitch project, itself. I’ve tried re-writing the function several different ways; they’re all error free, and they output the correct messages to the browser endpoint, but none of them will pass/validate when I submit to freecodecamp. I’ve been at it for days. Any new suggestions would be greatly appreciated. Thanks, everyone!

Your code so far
https://glitch.com/edit/#!/deserted-juniper
https://glitch.com/~deserted-juniper

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36.

Challenge: Use the .env File

Link to the challenge:

Hello there,

There was an issue with the testing script for this, but I was under the impression this was fixed.

So, just to see if it helps, could you try adding https://www.freecodecamp.org to the allowedOrigins array within server.js.

If that does not work, could you try adding the variables to your .env:

DISABLE_XORIGIN=true
XORIG_RESTRICT=false

I tried both of those suggestions, but neither of them work, unfortunately.

Just to mention it: You have an extra space in the allowedOrigins var:

'https://www.freecodecamp.org '

I just corrected it, but still no success. I’m not sure if they are related, but I also cannot get the next 2 exercises (mounting and chaining the middleware) to pass successfully, either. I have completed all other tasks.

I am getting this error in the freeCodeCamp browser console:

Access to XMLHttpRequest at ‘https://deserted-juniper.glitch.me/_api/use-env-vars’ from origin ‘https://www.freecodecamp.org’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.

I might have confused the DISABLE_XORIGIN variable. Set it to false.

Sorry for making you go back and forth.

I tried submitting it after changing DISABLE_XORIGIN=true to DISABLE_XORIGIN=false, but it still did not pass.

No worries about sending me back and forth. I am very grateful you are taking the time to help me with the issue!

I’ll gladly take any other suggestions you may have.

Hey there, change this:

"fcc-express-bground": "https://github.com/freeCodeCamp/fcc-express-bground-pkg.git"
  },

It worked for me.

Out of interest, when did you clone the boilerplate? Recently, or did you clone it a while ago?

Where do I put this “fcc-express-bground”: “https://github.com/freeCodeCamp/fcc-express-bground-pkg.git” syntax you’re suggesting? Do I replace the
var bGround = require(‘fcc-express-bground’);
in the server.js file?

I started this set of exercises 3 or 4 days ago.

I tried replacing what I had in the server.js file, as well as in the package.json file with the syntax you suggested. It still won’t validate, though.

Sorry, I should have been more specific.

I suggest you remove the other .env variables I told you to add, and your package.json should look like this:

{
  "name": "fcc-learn-node-with-express",
  "version": "0.1.0",
  "dependencies": {
    "express": "^4.14.0",
    "body-parser": "^1.19.0",
    "cookie-parser": "^1.4.3",
    "fcc-express-bground": "https://github.com/freeCodeCamp/fcc-express-bground-pkg.git"
  },
  "main": "server.js",
  "scripts": {
    "start": "node server.js"
  },
  "engines": {
    "node": "4.4.5"
  }
}
1 Like

It WORKED! Thank you! YOU ROCK!!!

1 Like