Skip to content

re: Tracing requests in Node.js? VIEW POST


Hi! pretty late but maybe this helps others, what I usually try is to inject the models or the services in the request, so from your router code you can do something like

    async (req, res, next) => {
        const id =
        const customer = req.context.customerService.get(id)
        /// ... process and return response

You should create the customerService in a previous middleware and inject it to the context, so you can access to it from the context, and the service can access to the context as well.

I wrote a blog post about it here

code of conduct - report abuse