Tell us what’s happening:
I am not able to pass the .env lesson. It works when run on a browser. But When I paste the link for validating. It does not pass.
and this is what I get
// running tests The response of the endpoint json should change according to the environment variable MESSAGE_STYLE
// tests completed
// console output
[Error: Not Found]
**Your project link(s)**
solution: https://replit.com/@tanmay1978/nodejson
**Your browser information:**
User Agent is: <code>Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36</code>
**Challenge:** Basic Node and Express - Use the .env File
**Link to the challenge:**
https://www.freecodecamp.org/learn/back-end-development-and-apis/basic-node-and-express/use-the--env-file
Create a .env file in the root of your project directory, and store the variable MESSAGE_STYLE=uppercase in it.
Why do you have this in your code?
if (process.env.MESSAGE_STYLE === "allCaps")
Also:
The response object should either be {"message": "Hello json"} …
You are returning this (which is not quite the same):
"message": "Hello Json"
Finally, ensure that you are submitting the repl live link to FCC (rather than the link to your code). This is the link which is directly above the webview window.
.env already exists, corrected my if condition to check for “uppercase”.
The if condition is to check if the .env variable has the word “uppercase” then change the message value to all capitals else should be default sentence case.
So you have passed now? BTW, I should have pointed out the bit in the instructions where it says that you can’t use a .env with Replit. You put the variable in your Secrets tab instead.
When I visit https://node.tanmay1978.repl.co/json, I get {"message":"Hello json"}. This means that your code is not responding to an environment variable.
If you have the environment variable saved correctly in your Secrets tab then visiting that url should get me {"message":"HELLO JSON"}.
I have .env file but it is not visible. I have used secret tab to create a KEY. If I change the KEY then I need to restart in order to reflect the change.
The reason for not working when you checked is because I had miss-spelled “uppercase”.