Basic Node and Express - Use the .env File

Hello,

This entire Node and Express section has been giving me a lot of trouble. The concepts are easy enough, but I keep getting stuck for hours on little issues like Replit bugs and submitting locally and stuff like that.

I thought I was good to go, but now I am stuck on this using the .env file challenge.

FCC says I need to use a Replit secret, so I went ahead and did that. I was able to access the mySecret variable that was generated, and it did equal uppercase, but my .get() function seems to not be running, altogether.

Could someone please lmk what is wrong with my code, hopefully for the last time this week?

Link to the Replit

Thank you.

To add onto what RandellDawson said, you shouldn’t store process.env.MESSAGE_STYLE into a variable. The way the test works is that the value of process.env.MESSAGE_STYLE will change in order to verify your results. If process.env.MESSAGE_STYLE is stored in a variable; your code will not correctly respond.

2 Likes

You can store it in a variable, but the variable needs to be reevaluated inside the handler.

If you just move the

const mySecret = process.env['MESSAGE_STYLE']

inside the handler, it should work.

1 Like

@camperextraordinaire @a2937 @lasjorg

Thank you all, for your helpful feedback.

I got rid of the mySecret variable, then accessed process.env['MESSAGE_STYLE'] from inside the handler, BUT added quotes around MESSAGE_STYLE, which I think was something that had messed me up on a previous attempt.

I guess you must omit quotation marks around variables inside the .env file, but still need them when accessing them from the outside, even for variables.

Actually I think that only applies when using Secrets.

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