[SOLVED] Backend Development > Challenge 6 .env Issues

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

Every attempt to pass the .env Challenge fails. Totally baffled as to what I am doing wrong.

When viewing the page, I see the expected message “HELLO JSON”.

If I change the MESSAGE_STYLE value to something other than ‘uppercase’ then I see the expected message “Hello json”.

(Structure of the messages above is the JSON object, {“message”: })

Your project link(s)

solution: boilerplate-express - Replit

let express = require('express');
let app = express();

app.use("/public", express.static(__dirname + "/public"));
/* -- This is from the next test, it too won't pass.
app.use(function (req, res, next) {
  console.log(`${req.method} ${req.path} ${req.ip}`);

app.get("/", (req, res) => res.sendFile(__dirname + "/views/index.html"));

app.get("/json", function(req, res){
    if (process.env.MESSAGE_STYLE === "uppercase"){
            {"message": "HELLO JSON"}
    } else {
            {"message": "Hello json"}

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Safari/537.36

Challenge: Use the .env File

Link to the challenge:

Figured this out… I would recommend that FCC update the instructions on this section to include these steps in order to have it work correctly.

The solution was to run

npm update --save

Solution Thread

That shouldn’t be needed but you seem to have gotten an old version of the fcc-express-bground package for some reason.

Not sure what is going with Replit but it doesn’t install the package when I click Run. I have to manually run the install from the Shell.