Here is the code for this challenge and I tried to see what is the value of the variable that I need to compare as you can see with the console.log(process.env.MESSAGE_STYLE)
But the output of that log is undefined in my console.
Can anyone enlighten me as to why is that?
The .env file is named demo.env and is in the root directory
thanks for responding. I got the program to work and it does I’ve the correct output locally, but it gets timed out on the tests and says the program does not change the output based on the value of the variable MESSAGE_STYLE
here is the updated code
require('dotenv').config()
let express = require('express');
let app = express();
app.get("/", func1);
function func1(req,res){
res.sendFile(__dirname+"/views/index.html")
}
app.use("/public", express.static(__dirname+"/public"));
app.get("/json", function(req, res) {
if (process.env.MESSAGE_STYLE === "uppercase") {
res.json({"message": "HELLO JSON"});
}
else {
res.json({"message": "Hello json"}); // Note the correct casing: “Hello json”
}
});
module.exports = app;
It looks like the issue might be with the naming of your .env file. The file should be named exactly .env for dotenv to load it correctly. Rename demo.env to .env and make sure it’s in the root directory of your project. That should solve the problem!