Cannot complete .env challenge

Tell us what’s happening:

I am trying to figure out the .env challenge, but the system cannot mark this as completed. I believe that the code i use is correct (have a look below) :

var express = require(‘express’);
var app = express();
const mySecret = process.env[‘MESSAGE_STYLE’]

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

As you can see above i use the secrets tab of replit cloud platform.

Could you please, give me a little help regarding this.

Thank you in advance.

My project link


Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:98.0) Gecko/20100101 Firefox/98.0

Challenge: Use the .env File

Link to the challenge:

You can’t check the value of the environment variable out here in the global space.

The tests work by changing the value of the environment variable, so you need to know this value when the GET runs, not when the app starts.

That was the problem.

I moved the const mySecret = process.env[‘MESSAGE_STYLE’] inside app.get() function and it worked.

Thank you very much for your support !