Tell us what’s happening:
Hi everyone , I’m stuck on the “Use the .env File” challenge in FreeCodeCamp’s Backend course. My Node.js app is live and works fine on Render and locally.
It meets the requirement to return the /json
response in uppercase when MESSAGE_STYLE=uppercase
, but FCC tests still fail. I’ve confirmed in my Render logs that process.env.MESSAGE_STYLE
is indeed uppercase
when accessed by my app.
I’m confused why the tests aren’t passing when the app functions correctly. Any help or insights would be greatly appreciated!
Here’s my code:
myApp.js
:
`JavaScriptlet express = require("express");
require("dotenv").config();
let app = express();
app.use("/public", express.static(__dirname + "/public"));
app.get("/", (req, res) => {
console.log("Hello Express");
res.sendFile(__dirname + "/views/index.html");
});
app.get("/json", (req, res) => {
// *** Trying to find the error ***
console.log("Valor de MESSAGE_STYLE en Render:", process.env.MESSAGE_STYLE);
const textStyle = process.env.MESSAGE_STYLE;
if (textStyle == "uppercase") {
res.json({ message: "Hello Json".toUpperCase() });
} else {
res.json({ message: "Hello Json" });
}
});
module.exports = app;`
.env
file content (in Render’s environment variables):
MESSAGE_STYLE=uppercase
Your project link(s)
My Github Repo: GitHub - Francogalfre/backend-freecodecamp: 🚀 Node.js project for freeCodeCamp’s APIs & Microservices course.
Challenge Information:
Basic Node and Express - Use the .env File https://www.freecodecamp.org/learn/back-end-development-and-apis/basic-node-and-express/use-the--env-file