Have a problem with passing "Use the .env File" of "APIs and Microservices" course

Hello everybody and Happy Easter to everyone.

This is the first time I asking question to the forum. Usually when I had some problems in the freecodecamp courses, sooner or later I would figure them out, but with six’s exercise of APIs and Microservices I just stuck. I don’t know what i’m doing wrong, but I just can’t pass this test. Only one thing I pretty sure of, there is probably some simple fix or something trivial that I missed, probably because I super dumb.

Okay, now less about the feeling and more about the data : I done all my previous tests on replit, so using “Secret” button I created variable MESSAGE_STYLE=uppercase (replit doesn’t allows to create .env’s), created the function : https://replit.com/@NotSure1/boilerplate-express#myApp.js,
clicked run and it’s somehow not found.
Okay, I said to myself (I doing that a lot recently), maybe it’s just a buggy environment. And so I cloned the repo from the github and created myself account on glitch (Glitch :・゚✧), where you can create .env’s file. I copied the function, created the same .env (MESSAGE_STYLE=uppercase ) and … I still failed. I don’t know what else to do. I pretty sure that function is right, with env’s I tried different combination to no avail.

So now, you guys, my only hope.

I don’t know why it’s saying Not found
but one thing you need to do is to move this

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

inside the route. As you need the value of the variable when the route is requested, not when the application start

try reading this post for more infos

After your reply I took another look at my code and realized that I commented out :

let absolutePath = __dirname + “/views/index.html”;
app.get("/", function(req, res) {
res.sendFile(absolutePath);
});

app.use("/public", express.static(__dirname + “/public”));

That’s why my code wasn’t working. Anyway, thanks a lot. Problem found : I’m an idiot. No one can fix that.

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