const r = process.env.MESSAGE_STYLE === 'uppercase' ? "HELLO JSON" : 'Hello json'
app.get("/json", (req, res) => res.json({ message: r }))
after manual running by button answer is Uncaught error outside test suite,
changed port bacause of error Error: listen EADDRINUSE: address already in use :::3000
if I start on other port, route works with response {
“message”: “HELLO JSON”
}
help figure out, plz
ILM
November 21, 2024, 10:08pm
2
get the env value inside the route not in the global scope
app.get('/json', (req, res) => {
//1
//const r = 'Hello json'
//if (process.env.MESSAGE_STYLE === 'uppercase') res.json({ message: r.toUpperCase() });
//else res.json({ message: r });
//2
if(process.env.MESSAGE_STYLE === 'uppercase')res.json({message: 'HELLO JSON'})
else res.json({message: 'Hello json'})
})
still failing test Uncaught error outside test suite
also used not arrow function, restarted terminal, other ports
ILM
November 22, 2024, 2:46pm
4
have you tried giving braces to the if/else?
if (process.env.MESSAGE_STYLE==='uppercase') {
return res.json({message: 'HELLO JSON'})
} else {
return res.json({message: 'Hello json'})
}
result same Uncaught error outside test suite
all tests past without npm start, autorun
this last returned after transformation of route ’ server should return json from the “/json” endpoint’
so I ran ‘npm start’ and after this action fails with “uncaught error” also tried on another laptop
lasjorg
November 22, 2024, 3:29pm
6
Make sure you are not submitting the URL with the /json
path. Just submit the root URL.
If that isn’t the issue, please post all your code, a repo would be nice.
BTW, if that is all your code, you are missing the export at the bottom of the file module.exports = app;
lasjorg
November 22, 2024, 5:08pm
8
I don’t know where you got that starting code from, but I would suggest you use the links given to you on the first challenge page.
ok, thanks, comming back to databases. After Boilerplate coderoad suggest to open new workplace and opens node+express or npm
ILM
November 22, 2024, 5:43pm
10
you should not have coderoad for this project, it was never set up to use with codedroad