Node.js 在express js中为请求对象分配默认值

Node.js 在express js中为请求对象分配默认值,node.js,express,connect,Node.js,Express,Connect,如何确保在express中处理的每个请求都可以使用特定对象 var somethingImportant = "really important"; var app = express(); // This is just a hypothetical example of what I'm after... app.mixThisInWithRequest({ somethingImportant: somethingImportant }); app.use(function (

如何确保在express中处理的每个请求都可以使用特定对象

var somethingImportant = "really important";
var app = express();

// This is just a hypothetical example of what I'm after...
app.mixThisInWithRequest({
    somethingImportant: somethingImportant
});

app.use(function (request, response, next) {
   console.log(request.somethingImportant);
});

在上面的例子中,是否有类似于
mixThisInWithRequest
功能的工具?

早在
应用程序中就将其添加到中间件中的
request
对象中。根据需要使用
链:

var somethingImportant = "really important";
var app = express();

app.use(function (request, response, next) {
    request.somethingImportant = somethingImportant;
    next();
});
app.use(function (request, response, next) {
   console.log(request.somethingImportant);
});

我想到了这一点,我只是想确保用暴力迫使它关闭不会伤害到任何东西……这并没有什么真正的暴力。这是快车/直达车。