Tell us what’s happening:
when I submit the link for my code the test fails, but my code is doing exactly what the assignment asks not sure what is wrong
Your code so far
app.get('/json',(req, res)=> res.json({"message": response()}))
/** 6) Use the .env file to configure the app */
const response = ()=>{
let resp = "Hello json"
if (process.env.MESSAGE_STYLE === 'uppercase'){
return resp = resp.toUpperCase();
}else {
return response = "Hello World";
}
here is a link to the gitch code
Combining automated deployment, instant hosting & collaborative editing, Glitch gets you straight to coding so you can build full-stack web apps, fast
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36
.
Challenge: undefined
Link to the challenge:
https://www.freecodecamp.org/learn/apis-and-microservices/basic-node-and-express/use-the-.env-file
Hello!
Could You post a link to Your glitch code?
You’re not using the file. The challenge asks You to create a MESSAGE_STYLE
variable, which must be on the .env file.
# Contents of the .env file
# Fill the following:
MESSAGE_STYLE=
I am using the env file though
on line 34 inside my if statement I cal process.env also there is an env file located underneath the views folder with the variable assigned. I didn’t see any env files when I started this assignment so I created my own. Is there another one somewhere that I should use?
Yes, You’re “using” the file, but it’s empty .
The .env file is used to setup the environment of the project, what’s going to be used to, for example, access the database (storing secrets/passwords and users). Every developer must create their own .env files for a NodeJS app , otherwise process.env
will try to find the variables from the current environment (the shell, the windows environment variables, etc.). So, this:
is what You had to do .
Now, to solve the challenge, simply add the text:
# .env file
MESSAGE_STYLE=uppercase
camperextraordinaire:
You can not see the true contents of another user’s .env on Glitch. This protects sensitive information from being seen.
That makes sense . Thanks for the clarification.
but isn’t my env file in the root?
Yes, it’s!
Could You write this right after the const response
, like this:
** 6) Use the .env file to configure the app */
const response = ()=>{
let resp = "Hello json"
if (process.env.MESSAGE_STYLE === 'uppercase'){
return resp = resp.toUpperCase();
}else {
return resp = "Hello World";
}
}
console.log(response())
Check the console logs (on glitch, on the left, click Tools -> Logs ). If You see the string HELLO JSON
then I don’t know why it doesn’t work xD.
true that was an unnecessary step, but even when that is removed the test still fails
the variable containing hello json? I tried that and that does not work either
I just look at your latest response function (below).
const response = ()=>{
let resp = " "
if (process.env.MESSAGE_STYLE === 'uppercase'){
return resp = resp.toUpperCase();
}else{
return resp = "Hello json";
}
}
What value do you think will get returned if process.env.MESSAGE_STYLE is uppercase?
I forgot to change that when I updated the code, but it’s fixed now and the test still fail
I am starting to think that freecode camp is testing for a very specific solution and that even though mine works it’s not the solution that they are looking for
turns out I was submitting the wrong link lol sorry and thanks for the help
1 Like