I get the correct answer on postman and replit but FCC does not get it

Tell us what’s happening:
Hello
Im working on the “Use the .env File” challenge from BackEnd development and APIs, I get te requested answer when I run it locally, also when I run it from replit.com (Which is what I have used for all previous challenges) the FCC checker keeps marking it as not passed: " The response of the endpoint /json should change according to the environment variable MESSAGE_STYLE"

Any suggestions or help?

Your project link(s)

solution: https://replit.com/@juliantabares1/boilerplate-express-1json

Your browser information:

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

Challenge: Use the .env File

this is my code:

process.env.MESSAGE_STYLE = "uppercase"

const fontStyle = process.env.MESSAGE_STYLE

let absolutePath = __dirname + "/views/index.html"

let middleDirname = __dirname + "/public"

app.get("/", function (req, res) {

    res.sendFile(absolutePath)

})

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

    let answer = { "message": "Hello json" }

    if (fontStyle === "uppercase") {

        answer.message = answer.message.toUpperCase()

        return (res.json(answer));

    } else {

        res.json(answer);

    }

});

If you check this out here, your code can’t respond to changes in the environment variable.

Got your point and thanks by the way.
I created a .env file on the root directory and stored there my environment variable:

#STYLE
MESSAGE_STYLE=uppercase

export const fontStyle = process.env[‘MESSAGE_STYLE’];

and called it from myApp file:

const fontStyle = process.env.MESSAGE_STYLE

Still cant get it to pass, it works when checked on replit or using post man, but not for the checker.

Any additional advice?

If its still outside of your GET request, it won’t work. In the original location, the environment variable is only checked once, but the tests try to change this environment variable and run a subsequent GET request.

1 Like

Thanks a lot mate, I really did not know it worked that way:“the environment variable is only checked once”

Challenge passed and good learning.

1 Like

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