Add .env to json response in back end exercise

Tell us what’s happening:
Im trying for an Hour to make this exercise:

Let’s add an environment variable as a configuration option.

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.

If you are working locally, you will need the dotenv package. It loads environment variables from your .env file into process.env . Install it with npm install dotenv . Then, at the top of your myApp.js file, import and load the variables with require('dotenv').config() .

Ihave tried so many different solution and none of them are accepted by the platform.
I have no problem when i know Im learning and there are specific answers accepted but if nor the hint or the help from other users is helping at all I cannot but to get pretty pissed about this process.

And if i have to post here avery time something like this happens and im only at the beginning of the module…well…is not very fluent or practical to study over here.

This is my last entry and NOTHING!

app.get("/json", (req, res) =>{

let message = "Hello Json"

process.env.MESSAGE_STYLE === "uppercase" ? message = message.toUpperCase() : message = message

res.json({"message": message})

})

Your project link(s)

solution: https://freecodecampdb.herokuapp.com

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36

Challenge: Use the .env File

Link to the challenge:

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