Basic Node & Express "HELLO JSON" test

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

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

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

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;

https://omniacrystalline-gitpod-950oa1f8j2l.ws-eu116.gitpod.io/?folder=/workspace/gitpod/1

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 :roll_eyes:

you should not have coderoad for this project, it was never set up to use with codedroad