jeremydaly / jeremydaly/lambda-api
Async operation before send
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 1.5k
- Forks
- 127
- Avg merge
- 31m
- Merged PRs (30d)
- 2
Description
Hello everyone!
I need to save some important data every time when the response is already available.
I have tried 2 approaches:
api.finally- does not allow us to use an async callback.
api.finally(async (req, res) => {
await saveAudit(req, res)
res.cors()
console.log('done')
})
- Tried to override the method
res.sendin a middleware - it looks like the send method can not include any async operations.
function auditHandler (handler) {
return (req, res, next) => {
res.sendRes= res.send
res.send = function (body) {
const data = {}
saveAudit(data)
.finally(() => {
console.log('finally', resData)
res.sendRes.call(this, body)
})
}
next()
}
}
As a result - the API does not work, but it works if we do not wait for an asynchronous operation.

Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue names api.finally and a res.send override as the relevant response-lifecycle entry points. Start by tracing those paths in the framework and checking how middleware and response completion are tested. The issue names no files or tests and does not define an accepted behavior, so completion requires maintainer agreement on the async ordering.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100