I need need help with full code the env. File on replit

Please actually interact with me. We will not just write the answer for you.

I tried and it is not working. I have been more than a week working and searching about this.

I can’t help you if you don’t actually interact with me.

Please answer these two simple questions:

  1. What is the message that you need to return?

  2. What is the value of the environment variable that you need to check for?

The answer to both is in the part of the instructions that I quoted above.

Answering these two questions is the very first step in fixing your code.

Well I am trying to use secret tab to add the variable but I don`t see any difference .

I don’t think that you are reading what I’m posting.

I’m sorry, but I can’t help you without some interaction from you. Good luck with your code.

Of course I read and I posted what my code is so far.

Hi @Elisart !

The link to share your replit code can be found here

As mentioned earlier, there are a few errors in your code.

First start by completing the first task.
store the variable MESSAGE_STYLE=uppercase in the secrets tab.

Hope this helps!
Look for Secrets (Environment Variables)

Here is the link to your editor

https://replit.com/@Elisart/boilerplate-express-4

You have this code:

app.get("/json", (req, res) => {
  var message = {"message": "Hello json"};
  if (mySecret=="uppercase"){
    message = {"message": "HELLO JSON"};
  }
    res.json(message);
});
  1. In the Secrets the key should be MESSAGE_STYLE and the value should be uppercase.

  2. You are not reading the environment variable. The mySecret variable is not assigned a value anywhere. You can just read the environment variable directly from process.env in the if statement.

if (process.env.MESSAGE_STYLE === "uppercase")

Thank you so much for the help guys. I try to submit it but it is still not working. It is not accepted . The response of the endpoint /json should change according to the environment variable MESSAGE_STYLE

I don’t understand why you put the if statement where you did. It doesn’t do anything.

Your code right now:

app.get("/json", (req, res) => {
  var message = {"message": "Hello json"};
  if (mySecret=="uppercase"){
    message = {"message": "HELLO JSON"};
  }
    res.json(message);
});
if (process.env.MESSAGE_STYLE === "uppercase")

The if statement I wrote was supposed to be used instead of the one you have if (mySecret=="uppercase").


You do understand that mySecret is an undeclared and unassigned variable, right?

It doesn’t somehow magically contain the environment variable. They are read from process.env and then whatever key you have given it, for example process.env.MESSAGE_STYLE.

Just think of it as an object you add properties to (key/value pairs).

const process = {
  env: {
    MESSAGE_STYLE: "uppercase",
	someOtherKey: "someOtherValue",
  }
}

process.env.MESSAGE_STYLE
// 'uppercase'

process.env.someOtherKey
// 'someOtherValue'

I might also suggest you revisit the JS section of the curriculum because you seem to have rushed it and are missing some basic knowledge which is very much needed for the later challenges in the curriculum.

I think Replit looks for the Environment Variables inside Replits “Secrets”.

I tried to use an env file before, and I resulted using Replits “Secrets” to use Environment Variables.

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