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?
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
as a second question, since I am uscing repl.it, 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)
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):
KEY=value
, 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
my bad , i didn’t explain myself properly.
I understood the new feature of repl.it 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
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.
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