Basic Node and Express - Use the .env File

Currently working on the .env file part of the course. I can’t submit my answer even if I think it’s correct. They asked me to change the JSON object response on the /json endpoint to uppercase if process.env.MESSAGE_STYLE is equal to uppercase I did so with this simple function :

app.get("/json" , (req,res) => {
  if(process.env.MESSAGE_STYLE == "uppercase")
  {
     res.json({"message": "Hello json".toUpperCase()});
  }
  else
  {
    res.json({"message": "Hello json"});
  }
 
});

it works on the endpoint but can’t submit my answer and move on to the next challenge

solution: boilerplate-express - Nix (beta) Repl - Replit

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

Link to the challenge:

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

1 Like

If you read the instructions for this challenge, all of your changes should be in myApp.js.

1 Like

I don’t think so because, in order to complete the .env challenge, I need to create the .env file in the server.js where I have my router I need to transform my response in the GET route handler on the /JSON endpoint

No. You must not change server.js

You should only edit the secrets tab and myApp.js

In server.js

/******************************************************
 * PLEASE DO NOT EDIT THIS FILE
 * the verification process may break
 * ***************************************************/
1 Like

I still can’t submit my answer, I have this error :
’ The response of the endpoint /JSON should change according to the environment
variable MESSAGE_STYLE (Test timed out) ’
I did all my changes on my App.js

Did you add a secret?

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

Your code works for me when I put the applicable environment variable described in the instructions. Did you add the MESSAGE_STYLE variable and value to the Secrets tab?

1 Like

Yes, I did that’s why I can’t understand where this error is coming from

Can you show us a screen shot of the variable and its value? You can click on the variable in the secrets tab to do this.

What url are you submitting for the challenge?

When you submit it, when you open your browser’s console, do you see if any errors showing there?

1 Like

message

There is the variable and the value, the URL that I am submitting is :

https://boilerplate-express.chakibkarmim.repl.co

Did you make sure to Stop and Restart the project after adding the Secret and any changes you made to the project?

1 Like

Yes, I did stop the server and restart it multiple times, and sometimes I don’t get anything even if I don’t change anything. I get “The repl didn’t wake up in time. Please try again in 30 seconds” this on my page

I noticed you changed something in your code that was not there 20 minutes ago.

Currently, you are not following the instructions.

It says:

Then, in the /json GET route handler you created in the last challenge access process.env.MESSAGE_STYLE

You are not accessing the environment variable from within the /json GET route. Instead, you have created a variable named mySecret that accesses the environment variable. Normally it would not make any difference in a real project, but the tests are manipulating the environment variable behind the scenes so unless you access it within the /json GET route, the tests will not pass.

1 Like

Yes, I was just trying if i ll have a different output

With this piece of code as my answer

app.get("/json" , (req,res) => {
  if(process.env.MESSAGE_STYLE == "uppercase")
  {
     res.json({"message": "Hello json".toUpperCase()});
  }
  else
  {
    res.json({"message": "Hello json"});
  }
 
});

And this URL as an answer submission I get this error :

Look at your if statement. Is that what you want to compare?

if(process.env.MESSAGE_STYLE == "uppercase--")
1 Like

I make these changes, just to make sure that my code work and apply changes to my output

When I now submit your project url, it passes all the tests.

1 Like

Well, I still have the same issue, could it be cookies or a cash problem?