I cant validate this challenge of reading .env file

I always this response when I try to validate my code: The response of the endpoint /json should change according to the environment variable MESSAGE_STYLE (Test timed out)

this is my code:

var express = require('express')
var app = express()

app.get('/json', function(req, res){
const mySecret = process.env['MESSAGE_STYLE']
if(mySecret == 'uppercase') {
res.json({message: "HELLO JSON"});
}else {
res.json({message: "Hello json"});

 module.exports = app;

Your project link(s)

solution: boilerplate-express-1 - Replit

Your browser information:

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

Challenge: Use the .env File

Link to the challenge:

Did you set the environment variable using the secret tab?

This endpoint https://boilerplate-express-1.gharsallihelmi.repl.co/json should by default return the uppercase response if you set the environment variable correctly.

Yes, I did. And I tested it successfully when its value is ‘uppercase’ and when it’s not.

and what link are you submitting?

the correct link ofc:

what value have you given to the env variable?

it just passed! that’s weird. All I changed was remove the “/” from the end of my submitted link. didnt know that could make a difference.

Thank you!After seeing your code I just realize my mistake is to use a var to be the value of message ,its ok to realized but cant pass the test.

1 Like

please create a topic showing the code you have written if you need help :slight_smile:

1 Like

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