Basic Node and Express - Use the .env File test is failing

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

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:


Could You post a link to Your glitch code?

here the link to my glitch code!/global-brisket

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:

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 :slight_smile:.

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 :slight_smile:.

Now, to solve the challenge, simply add the text:

# .env file

You can not see the true contents of another user’s .env on Glitch. This protects sensitive information from being seen.

You typically put the .env file in the root folder of the project.

1 Like

That makes sense :sweat_smile:. 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";

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.

It is. That is not the issue. The problem is your else statement code block in your response function. Should it really be returning “Hello World” if process.env.MESSAGE_STYLE is not equal to “uppercase”?

1 Like

true that was an unnecessary step, but even when that is removed the test still fails

You still need to return something if process.env.MESSAGE_STYLE is not equal to uppercase. What should it be?

the variable containing hello json? I tried that and that does not work either

Try again and I will look at the code.

I just look at your latest response function (below).

 const response = ()=>{
   let resp = " "
 if (process.env.MESSAGE_STYLE === 'uppercase'){
  return resp = resp.toUpperCase();
   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

Your latest code works for me as long as your .env is setup correctly. I remixed yours and added the applicable .env file. Can you post a screenshot of your .env file?

1 Like