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

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.

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

message

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

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

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

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 :

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

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

Still, the same error I don’t get the (Test timed out) part why do I have this error :grimacing:

PS: if I open the URL on a private tab it works but on a normal one no even if I changed the whole browser

It is no longer working. You seem to already have one app running (the old version of it) and when you click Run it is creating a new one and I am not sure which version has the correct code. Make sure to stop all of them and only start one instance.

Another option is to just fork your project so all your code goes to a new project, add the environment variable, and click Run and use the new url to submit. Then, I would delete the older project to not cause confusion.

1 Like

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