Hi everyone, I’m trying to implement a solution for the problem 6 of backend course in FCC, but seems I cannot solve it no matter what.
This is my code:
app.get("/json", (req, res) => {
const mySecret = process.env["MESSAGE_STYLE"];
let text = "Hello json";
if (mySecret === "uppercase") {
text = text.toUpperCase();
}
res.json({ message: text });
});
Thanks in advance everyone
This is the link of the challenge : https://www.freecodecamp.org/learn/back-end-development-and-apis/basic-node-and-express/use-the--env-file
This is my file:
let express = require("express");
let app = express();
require("dotenv").config();
// this send a file
app.get("/", (req, res) => {
res.sendFile(__dirname + "/views/index.html");
});
2;
// this append to the file a style file
app.use("/public", express.static(__dirname + "/public"));
// this send a json file
app.get("/json", (req, res) => {
const mySecret = process.env["MESSAGE_STYLE"];
let text = "Hello json";
if (mySecret == "uppercase") {
res.json({ message: text.toUpperCase() });
} else {
res.json({ message: text });
}
});
module.exports = app;
Please link your project too - what platform are you using?
1 Like
Other than what said above, I would add
Make sure to not include the /json
endpoint when you submit
1 Like
I did, the problem is, when I follow the heroku link and navigate to /json the json that I get is all lower case
I haven’t used Heroku in a while but I would suggest you read the Heroku docs on config vars
2 Likes
This is the content of .env MESSAGE_STYLE=“uppercase”
right, that is a very good point
Ok it worked! I was trying to check the outcome of the message on heroku when visiting the link/json and I wasn’t able to see the capital HELLO JSON 'cause I didn’t have the config var setted, now I changed it and It worked and passes the test as well on FCC. Thanks a lot to everyone.
ilenia
July 2, 2022, 8:26pm
16
Note for the future, if you have to write an env file again, no quotes
1 Like
system
Closed
January 1, 2023, 8:32am
18
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.