Basic Node and Express - Use the .env File

Being as though I have no idea what is going on with this section, I dont have anything to offer other than my code isn’t working. A more accurate description would be, the code I copied from the “get a hint” isn’t working…

const mySecret = process.env['.env']

var response = "Hello json".toUpperCase();

if (process.env.VAR_NAME === "allCaps") {
  response = "Hello json".toUpperCase();
} else {
  response = "Hello json";
}

solution: boilerplate-express - Node.js Repl - Replit

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36

Challenge: Basic Node and Express - Use the .env File

Link to the challenge:

The hint requires you putting it in the correct place for it to work. I don’t see a GET request handler in your code snippet?

Make sure to read the instructions very carefully. You are not doing what is asked in the instructions:

Then, in the /json GET route handler you created in the last challenge access process.env.MESSAGE_STYLE

Nowhere in the instructions does it tell you to reference any other environment variable other than MESSAGE_STYLE. Also, why are you comparing anything to the string “allCaps”?

I have retained less than zero from this section and have no idea on what is being asked or why. The only thing I have to offer is all of the code I have so far:

let express = require('express');
let app = express();
app.use("/public", express.static(__dirname + "/public"));

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

app.get("/json", (req, res) => {
  res.json({
    message: "Hello json"
  });
});

const mySecret = process.env['.env']

var response = "Hello json".toUpperCase();

if (process.env.VAR_NAME === "allCaps") {
  response = "Hello json".toUpperCase();
} else {
  response = "Hello json";
}

How many GET route handlers does your existing code have?

You have a /json route and handler right above your code.

You need to do the same again but this time the response is conditional. If the environment variable MESSAGE_STYLE contains uppercase you res an object with the message property set to an uppercase string, otherwise a lowercase string.


Idk, 2? Thats my guess and I’m sticking to it.

Maybe one day I’ll understand the language you’re speaking but that day is not today.

That is correct. Which GET route handler was created in the previous challenge? That is the one where you will need to write the code for this current challenge.