Getting .env file exercise to pass with Replit

I’m in the Basic Node and Express section of the Back End Development and APIs course, and I can’t seem to get my code to pass.

Link to exercise:


var express = require('express');
var app = express();
var response = "Hello json";
var mySecret = process.env['MESSAGE_STYLE'];

app.get("/json", (req, res) => {
  if (mySecret == "uppercase") {
    response = response.toUpperCase();
    message: response

The “response” changes depending on whether the secret MESSAGE_STYLE variable is “uppercase” or not, like the exercise asks, but I still can’t get it to pass.

Not sure what I’m missing, and any help would be greatly appreciated. Thanks!

Why is this floating out in the global space? Have you tried pulling it inside of your function?

Thanks for the reply. I just tried that and it’s still not passing.

What is your new code?

This should be moved too. If it lives in the global space, then your app only responds to the value of the environment variable when the app is started. Any changes are ignored.

1 Like

Thank you! Moving the mySecret code into the function did the trick :slight_smile:

1 Like

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