Basic Node and Express using the .envs

Basic Node and Express using the .envs
0

#1

I am very confused at how express works. I don’t see any of the /json files, I don’t understand how the index.html and css page interact with the express code. For the challenge, the code is getting the The response of "/json" does not change according to MESSAGE_STYLE

/** 6) Use the .env file to configure the app */ app.get("/json", function(req, res){ if(process.env.MESSAGE_STYLE == "uppercase") res.json({"message": "HELLO JSON"}); else res.json({"message": "Hello json"}) });


#2

Did you make the change in the .env file ?


#3

yes I am just confused at how everything works. How does the index.html know to use the myapp or is it the myapp that calls on the index.html


#4

I think this question does not make sense in Glitch. The website itself makes this connection, just like Codepen.


#5

Hi I just got your code to work but i had to comment out (Blankout) section 5 in myapp.js eg.

/** 5) serve JSON on a specific route */
//app.get("/json", function(req, res) {
// res.json({“message”: “Hello json”});
//});

as this section all so defines “message”.

you also have to define MESSAGE_STYLE in the .env file

Environment Config

MESSAGE_STYLE=uppercase

hope this helps!


#6

This one was abit tricky for me, I hope this helps anyone

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