This following JavaScript snippet works fine:
// generate next extry in order to upadate the
// country html table
app.get('/next', (req, res, next) => {
data.nextEntry()
.then(country => tpl.salesForCountry(country))
.then(html => res.send(html))
.catch(e => next(e))
})
However, I am asking myself why?
When the get route is called, the Lambda function executes and my custom function nextEntry
(it's async) generates a new json object which is then converted to HTML and finally sent back to the requester by calling send
of the response object (res).
But why is the reference of res
still available and not undefined
? Because the Lambda function execution (provided to the get route) has finished long before the HTML has been generated by the then
branches. Could somebody kindly point me to the right direction - THX