Problem with the .env test in API lessons

I added the environmental variable with the if-else conditions and everything works correctly (infact i can see the message in uppercase in the myapp/json). However when I copy and paste the url for testing it does not pass the test . I have refreshed and restarted the app but with same poor result. What’s wrong?

Your project link(s)


Your browser information:

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

Challenge: Use the .env File

Link to the challenge:

Hello there,

Remember, in programming, it is important to be as accurate as possible, and ensure to read the instructions letter for letter.

Is this what you are asked to respond with:

var response = "Hello World";
  if (process.env.MESSAGE_STYLE === "uppercase") {
  response = "Hello World".toUpperCase();

Hope this helps

hi and thanks for your reply but I honestly I didnt’ understand it O.o
THe piece of code is exactly what I wrote and if I opend the url with the final /jason endpoint i got the message in uppercase ( since the environmental variable is set up to be uppercase)
I have also added the else if condition but the effect was not different
Could you please be more explicit since for many of us english is not our first language, thank you :slight_smile:

Sure, no worries.

This is what you have written:

var response = "Hello World";

This is the instructions:

The response object should either be {"message": "Hello json"} or {"message": "HELLO JSON"} ,

Can you see the difference?

Click for answer:

You have written “world” instead of json. Also, watch the casing for the lowercase.

Hope this helps

as a second question, since I am uscing, the only way to add an environmental variable is bu using the secret icon, but in which file of the project should the env variable be placed then.
Accidentally I left the cursor in the jason package file, before the version of a dependancy and hit the “insert” button, so the env var was inserted there (which is obviously not the proper place)

ops, that was embarassing :stuck_out_tongue:

It is slightly annoying Replit added/took-away this feature, but the mechanism is practically the same. That is, using the SECRETS tab is equivalent to using a .env file. You can access the values and properties in exactly the same way (process.env.VARIABLE_NAME).

The only difference, is the way you write the keys and values. Instead of working in a text-based file (.env):


, you need to use the SECRETS tab to put the KEY as the property name, and the value as the value.

I would not use this feature. As I mentioned above, you access the environment variables in exactly the same way: process.env.VARIABLE_NAME

Hope this clarifies

my bad , i didn’t explain myself properly.
I understood the new feature of about using the SECRET tab. My doubt is that when I click “insert”, replit will insert the env var in the file I am working on ( I was working in the json.package which, I believe, is not the place where to store the env var): If I am working in the app.js file, then replit will insert the env var there…
my question is WHERE to insert the env var :slight_smile:

You do not need to use the insert feature at all. Replit have that to show you how you might access the evironment variable, but you are already doing that here:

Once you have added a variable to SECRETS, it is automagically available in your app. This is not how it is in the real world (local development) - more configuration is needed to tell your app how to read the environment variables, but Replit does this for you in the background.

Hope this clarifies

yes, eventually I got it working on the mongodb lessons… but I cannot connect the db so I am opening a new help request and hope you can give a look, since I have found similar problems and already followed all the steps but with no result :frowning:

this is my new ticket, please

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