Can't get this solution right, but it should work?

Store the variable MESSAGE_STYLE=uppercase in the .env file. Then tell the GET /json route handler that you created in the last challenge to transform the response object’s message to uppercase if process.env.MESSAGE_STYLE equals uppercase . The response object should become {"message": "HELLO JSON"} .

Here is my code:

app.get("/json", (req, res) => {
  if (process.env.MESSAGE_STYLE === "uppercase") {
    response = "Hello json".toUpperCase();
  } else {
    response = "Hello json";
  res.json({"message": response});

any help is greatly appreciated, i’m getting very frustrated because i followed the hint exactly… tried ternary operations, nothing is working but I get fine output. I’ve tried declaring response outside the get method, inside the get method, not sure what to do…

Welcome, ryan.

Would you mind sharing your project code link? It is difficult to tell, without seeing all of your code.

As it stands, it does not look like you have declared response. Also, are you sure you have added the variable and value correctly to a .env file?

1 Like – that didnt work

i declared response both inside and outside of the app.get (not at the same time) just to check each. I’m not sure where to declare my .env variable as there’s no .env file in the project

you need to crate the .env file, and the variable inside, if you don’t create it, you will never have this value: process.env.MESSAGE_STYLE

ok so I created this file in the root directory. do i need to name it anything specific? how do i get it into myApp.js?

It is a very specific kind of file that developers use. Therefore, it must be named .env (dot included).

It is not so much getting it into myApp.js. You can access the variables declared within it (e.g. MESSAGE_STYLE) by using this syntax:


If you are still a bit confused, I recommend you take a read of this:
How to Use Environment Variables the Right Way (

Hope this clarifies

ok so i made a “test.env” file in the root of the project, with process.env.MESSAGE_STYLE=uppercase;

then in myApp.js my code is:

app.get("/json", (req, res) => {
  if (process.env.MESSAGE_STYLE === "uppercase") {
    let response = "Hello json".toUpperCase();
    res.json({"message": response});
  } else {
    let response = "Hello json";
    res.json({"message": response});

and it still won’t work. I’m trying really hard to get past this one stupid test so I can continue but this is infuriating…

@ryan17stehle See above

Also, to add, this is not going to work in the .env file:


Reason being:
MongoDB and Mongoose, first challenge, how do i get the name of my default database? - General - The freeCodeCamp Forum

can you please just tell me the answer so i can move on? i’ve been trying to find solutions for hours now…

I cannot code it for you, but I will summarise the issues:

  • The file must be named: .env (nothing more. nothing less)
  • Variables within .env files are read as-is. So, whatever you put in will be included. If you have MY_VARIABLE=some value;, then this will be the case:
process.env.MY_VARIABLE === "some value" // returns false
process.env.MY_VARIABLE === "some value;" // returns true

What this lesson requires is:

  1. Create a .env file
  2. Create a variable MESSAGE_STYLE and give it a value of uppercase within the .env file
  3. Add the logic to myApp.js (you have done this correctly, last I saw)

Hope this clarifies

i created the file called .env already.
within that file, i typed only this: MESSAGE_STYLE=uppercase

thats what you’re saying to do but it’s not allowing me to pass.

in myApp i have process.env.MESSAGE_STYLE===“uppercase” which should evaluate to true

I did this to pass:

  • Forked your code
  • Added MESSAGE_STYLE=uppercase to a .env file
  • Ran the app
  • Submitted the Live App link

I did not change anything in your myApp.js. So, either the app is not running when you submit, or there is something wrong with your .env file (NOTE: I am unable to see your .env file, because it is default behaviour to hide this in Repl, and many other online editors, for safety)

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