Node.js 如何在http.request函数中使用res.redirect

Node.js 如何在http.request函数中使用res.redirect,node.js,http,redirect,Node.js,Http,Redirect,在请求结束后获得hh中的值后如何使用hh?请做一些关于异步代码的教程。你不明白我在下面强调的执行顺序 `var req = http.request(options, function(res) { hh=res.headers["last-modified"]; /* hh is global variable */ });req.end(); /*print the last modified time of file

在请求结束后获得hh中的值后如何使用hh?

请做一些关于异步代码的教程。你不明白我在下面强调的执行顺序

`var req = http.request(options, function(res) 
       { 
              hh=res.headers["last-modified"]; /* hh is global variable */

       });req.end();
      /*print the last modified time of file that stored in hh
       console.log(hh);

我了解执行顺序。我知道我必须在函数中使用console.log(hh)。但在我的实际程序中,我必须使用res.render('/show',{msg:'Greater'});但是在函数内部,我不能使用render函数。因此,我不能向用户显示任何消息。请在此提示中提供帮助。是的,您可以在
http.request
回调处理程序函数内部使用
res.render
。很抱歉,你的问题不太清楚,我无法进一步评论。
//this line executes at time T1.1
var req = http.request(options, function(res) {
  //This line executes at time T2.1, AFTER T1.1 and T1.2 
  hh=res.headers["last-modified"]; /* hh is global variable */
  //This line executes at time T2.2 and hh IS AVAILABLE NOW
  console.log(hh);
});
//This line executes at time T1.2
//hh is NOT SET YET. CANNOT USE IT HERE. This is what async means.
req.end();