Basic Node and Express - Use the .env File

Tell us what’s happening:
Describe your issue in detail here.

Even if I do the exercise well it does not consider it resolved, how can I go on?
I am a bit perprello and I have stopped here since yesterday.
in the “/ json” gives me {“message”: “HELLO JSON”}
if I change the environment variable instead {“message”: “Hello json”}
please help me i want to move on.

Your project link(s)

solution: https://replit.com/@marcomonkey93/boilerplate-expressjson

Your browser information:

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

Challenge: Basic Node and Express - Use the .env File

Link to the challenge:

Create a .env file in the root of your project directory, and store the variable MESSAGE_STYLE=uppercase in it.

Then, in the /json GET route handler you created in the last challenge, transform the response object’s message to uppercase if process.env.MESSAGE_STYLE equals uppercase. The response object should either be {“message”: “Hello json”} or {“message”: “HELLO JSON”}, depending on the MESSAGE_STYLE value.

Note: If you are using Replit, you cannot create a .env file. Instead, use the built-in SECRETS tab to add the variable.

Note the text “…if process.env.MESSAGE_STYLE equals uppercase…” in the assignment description above. How do you code that in JavaScript? Is that what you have in your Replit code?

Also, make sure that, since you are using the Replit you need to use the built-in SECRETS tab to add the variable.

I see the following on line 5 of your myApp.js file:

const mySecret = process.env['MESSAGE_STYLE'];

You reference mySecret in the /json get request callback. The problem is, if the environment variable is changed (like our tests do), it will always be what you originally assigned the environment variable MESSAGE_STYLE (or Secret in replit). To prevent this issue, you need to make sure to assign this within the callback request before checking its value for the return response.