Hi,
I am doing the Basic Node and Express course and I am stuck on the “use the .env file” lesson.
I keep getting this error message:
// running tests The response of the endpoint
/json
should change according to the environment variable
MESSAGE_STYLE
// tests completed
The response of the endpoint /json
should change according to the environment variable MESSAGE_STYLE
And yet when i go to the json endpoint I get “HELLO JSON” in all caps, and if I change the variable name to something wrong it reverts back to lower case so i don’t know what I am doing wrong.
Here is my code for this exercise:
\\\
let express = require('express');
let app = express();
console.log("Hello World");
/*
app.get("/",
function(req, res) {
res.send('Hello Express');
})
*/
if (process.env.MESSAGE_STYLE==="uppercase") {
response ="Hello json".toUpperCase();
} else {
response ="Hello json";
}
app.get("/json",
function(req,res) {
res.json({"message":response});
})
app.use("/public", express.static(__dirname + "/public"));
app.get("/",
function(req,res) {
res.sendFile(__dirname + "/views/index.html");
});
\\\
And my environment variable is stored by replit as
Key: MESSAGE_STYLE
Value: uppercase
Any help would be greatly appreciated!!
Your project link(s)
solution: boilerplate-express-1 - Replit
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 6.3; Win64; x64; rv:100.0) Gecko/20100101 Firefox/100.0
Challenge: Use the .env File
Link to the challenge: