I'm struggling with returning an object in JSON format using Express. What's confusing me is the following code snippet:
class Greeting {
Greeting(name) {
this.name = name;
}
get name() {
return name;
}
}
app.get('/json/:name', function (req, res) {
greeting = new Greeting(req.params.name)
greeting.something = req.params.name
res.json(greeting)
})
http://localhost:3001/json/someparam
Output:
{
"something": "someparam"
}
Why is the name set in the constructor not being returned as well?