.env file challenge json

Tell us what’s happening:
Describe your issue in detail here.
I am trying to do the challenge using .env file. I am using replit and have made the secret as explained rather than creating a .env file. I then have a const value,
const MYSECRET = process.env['MESSAGE_STYLE']

then

app.get('/json', (req, res) => {
  if(MYSECRET === 'uppercase') {
     resp = {"message": "Hello json".toUpperCase() }
     res.json(resp)
    console.log(resp)
  } else { 
      res.json({"message": "Hello json" })
  }
  
})

Ive logged the response to console to ensure it is changing to uppercase. but the test still fails saying

The response of the endpoint

/json

should change according to the environment variable

MESSAGE_STYLE

Your project link(s)

solution: boilerplate-express - Replit

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.61 Safari/537.36

Challenge: Use the .env File

Link to the challenge:

If you check the environment variable a single time in the global scope, then it’s impossible for your app to respond to changes to the environment variable. The tests work by changing the environment variable while your app is running.

Thanks removing the const value for MYSECRET and moving process.env['MESSAGE_STYLE'] into the if statement worked.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.