Problem with passing Basic Node and Express - Use the .env File

Problem with passing Basic Node and Express - Use the .env File
0

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

/** 6) Use the .env file to configure the app */

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

:roll_eyes:I try also inner, and also

process.env.MESSAGE_STYLE="uppercase" 
if (process.env.MESSAGE_STYLE === "uppercase") {
app.get('/json', function (req, res ) {
  res.json(JSON.parse(JSON.stringify({"message": "HELLO JSON"})));
  })}


https://learn.freecodecamp.org/apis-and-microservices/basic-node-and-express/use-the--env-file


Still cannot pass Use the .env File
#2

You need to set MESSAGE_STYLE in the .env file and configure the route in your application code.


#3

And this is not?
process.env.MESSAGE_STYLE="uppercase"
because just .env get error.
.MESSAGE_STYLE in .env is file, is not?
this also not work
res.json[“message”] =“HELLO JSON”;


#4

Make sure you are setting only MESSAGE_STYLE, not process.env.MESSAGE_STYLE in the .env file.


#5

I tryed by instruction MESSAGE_STYLE=uppercase or MESSAGE_STYLE=“uppercase” first, but the error is not defined evaluated.


#6

Also make sure you do not have process.env.MESSAGE_STYLE being set in your code.


#7

I did it, that couldn’t work.


#8

This is incorrect
27%20PM

Do not set MESSAGE_STYLE in myApp.js.

Set it in the .env file.

33%20PM


#9

I am disappointed how is it described in instructions. word “store” and the similar describing of env. file They said about process and vuala something “shell file” and you must now is not the same.

But still not woking
I also rewrite the previous, but not noNOT NNOT worked.

PLEASE HELP.

https://glitch.com/edit/#!/atom-earthworm
app.get(’/json’, function (req, res ) {

res.json(JSON.parse(JSON.stringify({“message”: “Hello json”})));
})

/** 6) Use the .env file to configure the app */
if (process.env.MESSAGE_STYLE == “uppercase”)
{console.log(process.env.MESSAGE_STYLE)
app.get(’/json’, function (req, res ) {

res.json(JSON.parse(JSON.stringify({“message”: “HELLO JSON”})));
})}


#10

I now get uppercase, but the solution is not accepted.

var message ={"message": "Hello json"}
/** 5) serve JSON on a specific route */

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

  res.json(message)
})}

#11


and if you look here the message is uppercase
https://atom-earthworm.glitch.me/json
At first look you maybee ask how that should work?
I check that first ouput is lower case and second uppercase
I also try parse and stringify

and console

Could not find node 5.4.5, using 8

what if test is not updated


#12

Please do not create multiple topics for the same issue. I have merged your two topics.


#13

Nobody answer two days!!! because they think is old problem and solved!!!
I also try others in curriculum they also dont work this is urgent.If nobody answer that mean none really solved.


#14

There is a limited number of people who would even be able to help you with this. An ongoing conversation thread is more likely to solve your problem than starting over several times and it clutters the forum and makes the search functionality less useful for future users who are searching for a solution to the same problem.


#15

Hi. You have 2 app.get() functions listening for the same path. You should only have 1 now. Comment out the app.get() from the previous lesson.

EDIT: I see that you’ve already done the other lessons. You may be having trouble with the URL that you submit during the lesson (like I was). Make sure it is https://atom-earthworm.glitch.me/ instead of https://atom-earthworm.glitch.me/json. You don’t need the /json


#16

believe me I try both in all variations.
https://atom-earthworm.glitch.me/json I already try put instead get, without get, with if inner get. there must be a malfunction
The response of “/json” does not change according to MESSAGE_STYLE


#17

I’ve looked at the test code in the repo. If you put https://atom-earthworm.glitch.me/json link in your submit field for the lesson, it won’t work. You have to submit it without the /json in the URL that you submit. I was able to pass by doing this.


#18

Try to comment the case 5, maybe the get request is trapped there


#19

do you have mind ** 5) serve JSON on a specific route /
/

app.get(’/json’, function (req, res ) {
res.json(message)
})

//
I try again, but no and before that one advice me to comment
** 5) serve JSON on a specific route /
/

app.get(’/json’, function (req, res ) {
res.json(message)
})

//


#20

I put the if statement inside app.get function, maybe that did it.

Here is how I solved it. I commented out the previous solution and

app.js

/** 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”
})
}
res.json({
“message” : “Hello json”
})
})

.env

MESSAGE_STYLE=uppercase