node.js使HTTP服务器的请求和响应全局化? [英] node.js make request and response global for HTTP server?

查看:80
本文介绍了node.js使HTTP服务器的请求和响应全局化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始使用node.js,并通过 http://nodebeginner.org/index.html .很好的入门教程,但我真的很想知道是否可以将请求和响应都设为全局",以便为当前传入请求加载的任何模块都可以访问它们……而不是注入.

I've just started on node.js and ran through http://nodebeginner.org/index.html. Great start tutorial but I really want to know is it possible to make both request and response 'global' so any module loaded for the current incoming request can access these... rather than injecting.

想法?

推荐答案

与大多数Web脚本语言不同,在Node中,来自不同客户端的许多HTTP请求可以同时处于活动"状态.您怎么会知道您要回应哪个客户?

Unlike most web-scripting language, in Node many HTTP requests from different clients can be 'active' at the same time. How would you ever know which client you're responding to?

因此,尽管您认为在任何给定时间只有1个请求和响应,但实际上所有当前客户都有未解决的请求.

So while you think there's only 1 request and response at any given time, there are actually open requests for all current clients.

这篇关于node.js使HTTP服务器的请求和响应全局化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆