Basic Node and Express - Use the .env File

Tell us what’s happening:
Describe your issue in detail here.
I’m currently stuck at this point and I need help
Your project link(s)

solution: boilerplate-npm - Replit

Your browser information:

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

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

Link to the challenge:

Well, nothing looks wrong with the code, but by design I can’t see your secret. Did you create a secret variable in the Replit? When I go to the link, it returns Hello json in lowercase… does it also do that when your secret var is set to uppercase?

Oh, just noticed you have an extra space in the word uppercase — "uppercase ". That might be causing an issue. Also, not sure if not having quotes " around the word message in your JSON responses would cause an issue or not.

What do I type in the key and value boxes?

I’m assuming you mean in the Replit secret?

The KEY would be the variable name… in this case your MESSAGE_STYLE. Then the value would be what you want to set MESSAGE_STYLE to.

Ok!
Thanks, I will try that.

You had directly messaged a few people regarding this. If you’re still having problems, can you send a screenshot of your private keys so we can see what they look like to compare it to your code?

@kinome79


Here’s the screenshot.

Ah, what I meant was a screenshot of your private keys… could you click on secrets and share a screenshot of what they look like? We can view your code via your Replit link, but the one thing we can’t view is your secret variables, because they are… well… secret :slight_smile:

image

Could you try putting uppercase in quotes and make sure it is saved? ← Nevermind… doesn’t seem to need quotes

Actually, nevermind. I guess they don’t need to be in quotes… you cropped the bottom of the window, are you sure its saved… like underneath does the button say “Add New Secret”… I’m thinking it hasn’t been saved.

Oh, and another thought… since you’ve modified the secret, have you stopped and started your code again? I loaded my old project for this, and when I modify the secret (like change it from uppercase to lowercase, the change doesn’t take affect until I stop the code, and restart it.

How do I restart the code?

Stop and Play button.

You removed the export from myApp.js add it back.

module.exports = app;


As an aside, I wouldn’t suggest putting the logic inside the res.json

Wow, good catch. I assumed it was scrolled off the page and just focused on troubleshooting the logic code.

What lasjorg said is correct… assuming your secret is saved… the original file had that export at the bottom of the page… yours does not.

Oh…kk!
Where is the logic if I may ask?

The ternary inside the res.json. I would avoid any code logic directly inside that.

  • Just as a code style and for readability, I would prefer not to have code logic inside it.

  • I would avoid having the server send the result of an expression without being able to check it first if needed.

Thanks guys.
I have finally passed it :pray: :people_hugging:

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