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?

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";
}

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.

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