Problem completing .env challenge

Basic Node and Express - Use the .env File ->
having a problem with submitting the challenge

var response = "Hello World"; 

app.get("/json", function(req, res) {
  console.log(process.env.MESSAGE_STYLE,"<=message style");
  if (process.env.MESSAGE_STYLE === "uppercase") {
  res.json({
    "message": response.toUpperCase()
  })
  } else {
  res.json({
    "message": response
  })
}

My .env file configration ->

MESSAGE_STYLE=uppercase

getting Error says :sleepy:

// running tests The response of the endpoint

/json


should change according to the environment variable

MESSAGE_STYLE


// tests completed

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 11_1_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.101 Safari/537.36.

Challenge: Use the .env File

Link to the challenge:

Did you ever get this to pass? If not, I can help. Took me 4 hours to figure out what I was doing wrong, lol.

Here’s my solution just in case…

var express = require('express');
var app = express();


// Normal usage
app.use(express.static(__dirname + "/public"));


app.get('/', function(req, res) {
res.sendFile(__dirname + '/views/index.html');
})

app.get('/json', function(req, res){

if(process.env.MESSAGE_STYLE==='uppercase'){
  res.json({
  "message": "HELLO JSON"
})
} else {
    res.json({
  "message": "Hello json"
})
  };
});

Remember to create a new file called .env with the following variable:

MESSAGE_STYLE=uppercase
1 Like

hmmm…this one didnt work for me