Trying to complete challenge in : Back end Development and APIs: "Use the .env File"

I’m using replit to complete the back-end challenges. I am currently stuck on the 6th one in Basic Node and express, this is my code below:

const mySecret = process.env['MESSAGE_STYLE']

app.get("/json", (req,res) =>{
  if (mySecret == "uppercase") {
      "message": "HELLO JSON"
  } else {
        "message": "Hello json"

I inputted the secret and it prints out correctly when I use console.log(mySecret). It does not pass the test though.

Your project link(s)


Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:90.0) Gecko/20100101 Firefox/90.0

Challenge: Use the .env File

Link to the challenge:

1 Like

Hello delaine,

Did you managed to complete it? I’m having the same problems.


EDIT: Found a link with code that works, still don’t know why mine didn’t work
Useful Replit

Hi Luis,

I did complete it, but a while ago now, I really should have written down my solution when I figured it out. Nevertheless, I think I ran npm install dotenv and then placed the following at the top of my file require('dotenv').config(). If this doesn’t work let me know and I’ll do all I can to help.

Good Luck!

You can’t check the value of the secret out here in the global space. Your app can’t respond to changes in the env between GET calls if you only check the environment variable once out here.

Edit, oh, this is an old post.