I have a challenge solution but it doesn’t work due to :
SyntaxError: Unexpected token < in JSON at position 0 at JSON.parse ()
and
Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client error.
How can i fix this?
glitch - https://glitch.com/~try-nodejs
Challenge: Use the .env File
Link to the challenge:
Learn to code. Build projects. Earn certifications.Since 2015, 40,000 graduates have gotten jobs at tech companies including Google, Apple, Amazon, and Microsoft.
1 Like
try a code like this:
let myMessage="message content";
res.json({
message:myMessage
})
your code was fine at the first time, I just wanted to tell you to use message instead of "message"
the same error
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})
}
})
try without a "" quote mark with message
like {message:yourmessage} not like {"message":yourmessage}
Same error here:
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})
}
})
Combining automated deployment, instant hosting & collaborative editing, Glitch gets you straight to coding so you can build full-stack web apps, fast