Validating breaks page

When attempting the " Use the .env File" challenge, In my replit, I’ve managed to get it to where the text will be capitalized if the enviornment variable “MESSAGE_STYLE” is set to uppercase, and the message is displayed as expected, but when I link it on the challenge page and hit “I’ve completed this challenge” my replit throws the following error:

SyntaxError: Unexpected token N in JSON at position 0
at JSON.parse ()
at /home/runner/boilerplate-express-1/node_modules/fcc-express-bground/index.js:92:26
at IncomingMessage. (/home/runner/boilerplate-express-1/node_modules/fcc-express-bground/index.js:33:7)

Your project link(s)

solution: https://replit.com/@UnusualFrog/boilerplate-express-1#myApp.js

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:89.0) Gecko/20100101 Firefox/89.0

Challenge: Use the .env File

Link to the challenge:

Why is most of your logic for the function floating around in the global space? This is causing some trouble for you

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

All of that should be inside of your GET route handler (which should be for /json)

Thanks for the response!
I moved the coed into the GET route handler like you suggested, but I seem to still be experiencing the same issue(renders the way I expect until validation attempt on the challenge page) with the same error message I posted above

I also change my target for the handler to ("/json") from ("/") but now only “Not Found” is rendering to the page, what should I do about that?
thanks again

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