Basic Node and Express - Use the .env File

Tell us what’s happening:
Describe your issue in detail here.

Hello guys.

I can’t finish this challenge. Read a lot of help topics, but still can’t recognize the problem. I’ve got an error message: The response of the endpoint /json should change according to the environment variable MESSAGE_STYLE.
Can someone please check my code:

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/ Safari/537.36

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

Link to the challenge:

res.json("{message: Hello Json")

This is bad syntax. The previous res.json is the correct syntax. Also, you should check the capitalisation carefully for the second res.json.

1 Like

Thanks! I fixed syntax and capitalization issues. I hope so at least. But error message still the same.

If you want to share your working code, it’s better not to post screenshots.
Also the link to your repl code should be: boilerplate-express - Replit
(The url in your address bar when you’re on your repl).
The link you shared is the live link for submitting your code for FCC testing.

That said, your code is now correct. Perhaps you haven’t correctly added your environment variable to your Secrets tab in repl?

Ok, thanks! I made .env file with this variable:
“const mySecret”: “process.env[‘MESSAGE_STYLE’]”

And this is my url then: boilerplate-express - Replit

I can’t see an env file in your repl. That’s good though, because you shouldn’t have one. In replit, your environment variables are stored in your Secrets tab.
In either case, you should be storing the variables as:

1 Like

Sorry for the scrshot, but still can’t understand correct way of giving name on Secret tab, I did it like this:

see here:

1 Like

When you open up your Secrets tab, you can view environment variables which you have already stored and/or add new variables.

You should add them exactly as the NODE_ENV variable is added here (i.e. no additional syntax such as brackets, quote marks etc).
This variable will then be available in your app as process.env.NODE_ENV.

You would ordinarily create a .env file and add this variable as NODE_ENV=test, but this is how replit chooses to handle environment variables, so that they are not publicly visible.

All of this is also explained in some detail in the challenge instructions which you linked earlier.

1 Like

Yes, for this one, thank you! But still don’t understand how it should be fixed exactly in this case, like this?

If you’ve now added your environment variable correctly, your code should now pass on FCC.

1 Like

yes that is how you set it exactly
(then click save)

1 Like

Unfortunately issue still the same…

I just submitted your live repl link and it passed for me.

1 Like

Yep, magic, now it’s working :slight_smile: Thank you!

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