Error in use-the-.env-file challenge

I have the erro:

SyntaxError: Unexpected token < in JSON at position 0
    at JSON.parse (<anonymous>)
    at /rbd/pnpm-volume/f9f48ebe-a675-40ba-8bbc-70c96c29a2c2/node_modules/.github.com/freeCodeCamp/fcc-express-bground-pkg/597d66d2cc536e746e1603d0332246317d515f79/node_modules/fcc-express-bground/index.js:80:26
    at IncomingMessage.r.on (/rbd/pnpm-volume/f9f48ebe-a675-40ba-8bbc-70c96c29a2c2/node_modules/.github.com/freeCodeCamp/fcc-express-bground-pkg/597d66d2cc536e746e1603d0332246317d515f79/node_modules/fcc-express-bground/index.js:29:26)
    at IncomingMessage.emit (events.js:189:13)
    at IncomingMessage.Readable.read (_stream_readable.js:487:10)
    at flow (_stream_readable.js:953:34)
    at resume_ (_stream_readable.js:934:3)
    at process._tickCallback (internal/process/next_tick.js:63:19)

The code seams right:

app.use('/json', (req, res) => {
  let myMessage = "Hello json";
  
  if(process.env.MESSAGE_STYLE === 'uppercase') {
    return res.json({message:myMessage.toUpperCase()})
  }else {
    return res.json({message:myMessage})
  }
})

Challenge: Use the .env File

Link to the challenge:

1 Like

@ramonm_pacheco, Try without the word return
If code fails, refresh/close the browser and reopen then submit again, try few times. Try another day if necessary.

** However, for your information: never hit the button ‘Format This File’ in glitch until you finish all the challenges, just write your code simply in your own way for any of your glitch challenge/project.

I am having the exact same error, I tried all different solutions but keeop on getting the syntaxError mentioned at the top of this post.
My app displays the correct json object, but when I try to link to my solution in freecodecamp I get that error.

I’ve been trying for days, same boring error:

SyntaxError: Unexpected token < in JSON at position 0
11:14 AM
    at JSON.parse (<anonymous>)
...
Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
11:09 AM
    at ServerResponse.setHeader (_http_outgoing.js:470:11)

@ramonm_pacheco, you can skip this test and move to the next one for the moment, or you have also other choice some people are making this on another platform, you can read it here alternative to glitch the last reply for the moment, they are saying that it’s working, but I didn’t check any of the alternative mentioned there

I’ll follow your advice @thetradecoder and try an alternative opt, because Glitch is not good. Thanks for your help.

The .env file is a private file that people who don’t own the project can’t see. Since you can create anonymous projects using repl.it, you need to create an account to have private files. You need to create the .env file before running the code.