Use the .env File with replit.com

Tell us what’s happening:
Even though the json route is working with ifElse, I don’t know why I can’t be approved in this lesson.
Can someone help me?

myApp.js

var express = require('express');
var app = express();
console.log("Hello World");

absolutePath = __dirname + '/views/index.html';
absolutePath1 = __dirname + '/public';

app.get('/', (req, res) => {
  // res.send("Hello Express");
  res.sendFile(absolutePath);
  app.use('/public', express.static(absolutePath1));
});
const mySecret = process.env['MESSAGE_STYLE'];

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

Your project link(s)

solution: https://replit.com/@diegodmitry/boilerplate-expressjson

Your browser information:

User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:98.0) Gecko/20100101 Firefox/98.0

Challenge: Use the .env File

Link to the challenge:

The tests work by changing the environment variable. But you check the value a single time and save the result into a global variable, so you app can’t respond at runtime to changes in the environment variables.

I did the check without the variable and it worked.
Thanks for your feedback.

To confirm, all tests pass now?

1 Like

Yeah! All tests pass now. Thanks!

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