Api and Microservices/Basic Node and Express/ Use the .env file

greetings!

I have been trying to solve this challenge but it keeps prompting that test failed with the message:

The response of the endpoint /json should change according to the environment variable MESSAGE_STYLE

Link to my solution on repl.it: https://replit.com/@iitdelhi2017/boilerplate-express

User agent: Google Chrome , Windows 10 Pro version 2004

Challenge: Use the .env File

Link to the challenge:

Any help would be splendid.

Thank You

const mySecret = process.env['MESSAGE_STYLE']

mySecret is initialized only when the app is started, so it will only ever be what you have specified it to be in the environment variable once the app is started. Behind the scenes, the test changes the value of the environment variable without restarting your app while making calls to the /json endpoint. Move the mySecret initialization to be inside the handler, so it gets set each time the environment variable gets changed behind the scenes.

1 Like

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