.env file for node

.env file for node
0.0 0

#1

Hello, I’m doing the node and express exercises and I’m stuck on the .env file. The goal is to write “Message_Style=uppercase” in the file and then use that to change the api call from the previous exercise.
I can’t think of what that really means though. Here’s my best guess:

app.get(’/’, function(req,res) {
if(process.env.Message_Style === ‘uppercase’){
res.send({message: ‘HELLO JSON’);
}
else {
res.send({message: ‘Hello json’});
}

This works I guess but it won’t accept it as an answer. I only get “Unexpected token N in JSON at position 0” as an error.


#2

how does your .env file look like?


#3
# Environment Config

# store your secrets and config variables in here
# only invited collaborators will be able to see your .env values

# reference these in your code with process.env.SECRET

SECRET=
MADE_WITH=
MESSAGE_STYLE=uppercase

# note: .env is a shell file so there can't be spaces around =

#4

I’ve edited your post for readability. When you enter a code block into the forum, precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.


#5

I see the problem now.

Then tell the GET /json route handler

You are not giving it a correct route.