简体   繁体   English

nodejs中express-http-context的用途是什么?

[英]what is the use of express-http-context in nodejs?

i cant find the documentation for bindemitter in express-http-context.what is the use of this particular method?我在 express-http-context 中找不到 bindemitter 的文档。这种特定方法的用途是什么?

 httpContext.ns.bindEmitter(req);
  httpContext.ns.bindEmitter(res);

bindEmitter is a function provided by one of express-http-context 's dependencies, namely cls-hooked and is described on their documentation : bindEmitter是一个 function 由express-http-context的依赖项之一提供,即cls-hooked并在其文档中进行了描述:

Bind an EventEmitter to a namespace.将 EventEmitter 绑定到命名空间。 [...] [...]

The most likely time you'd want to use this is when you're using Express or Connect and want to make sure your middleware execution plays nice with CLS, or are doing other things with HTTP listeners [...]您最可能希望使用此功能的时间是您使用 Express 或 Connect 并希望确保您的中间件执行与 CLS 配合良好,或者正在使用 HTTP 侦听器执行其他操作 [...]

So it basically allows you to ensure that req/res will be within the scope of the namespace that express-http-context has created and that this context is not lost.因此,它基本上允许您确保req/res将在express-http-context创建的命名空间的 scope 内,并且此上下文不会丢失。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM