DEV Community

Discussion on: Simplify your Node code with Continuation Local Storage variables

Collapse
 
miketalbot profile image
Mike Talbot ⭐

You are right, it's pretty like response.locals in Express (app.locals are really rather global), I haven't used KoaJS. The difference being that you don't have to pass response through to every function you call as cls is defined as a require.

Collapse
 
renoirb profile image
Renoir

Koa with ctx.state is unique per request per user. Look the source up, it's great. I prefer it to Express. It's actually from some folks from Express. But the API is more modern. I imagine that Express 5 (in beta?) is inspired by it

Thread Thread
 
miketalbot profile image
Mike Talbot ⭐

Looks from the docs that you are still supposed to pass it on though? It's not a global like cls unless I'm missing something. If that's the case then you put it in cls and never pass it through function layers, callback and events etc.