J
J
jenya77712020-01-02 00:02:19
Node.js
jenya7771, 2020-01-02 00:02:19

How to add an intermediate handler before res.json() in ExpressJs?

Hello, I have the task of counting how long the request was executed, and logging the request and response, and for this I need to perform logging before answering the user and calculate how long the request was executed.
How to make it more and more beautiful, add an intermediate handler not at the beginning of the application, but at the end?

This is how I plan to do the first timestamp:

app.use((req, res, next) => {
    req.startTimer = Date.now()
    next()
})

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Yarkov, 2020-01-02
@yarkov

Before inventing the bicycle, you need to google

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question