node.js和console.log中connect-flash的区别?

时间:2013-03-25 17:15:45

标签: node.js express console.log

据我所知,两者都是服务器打印输出。我尝试使用下面的flash,我只看到控制台打印输出。

app.get('/', function(req, res){
    console.log('hi there!');
    req.flash('info', 'flash test');
    req.end();
});

闪光灯使用的是什么以及我应该如何使用?

1 个答案:

答案 0 :(得分:3)

Flash消息会显示给查看您网站的用户。 console.log显示在运行服务器的控制台上。

connect-flash是实现Flash消息的中间件。下次用户查看页面时,Flash消息将显示在用户浏览器上。闪存通常与重定向结合使用,确保消息可用于要呈现的下一页。这就像是查看最后一页的提示。

//go to /flash page
app.get('/flash', function(req, res){
  req.flash('info', 'Hi there!')
  res.redirect('/');
});
//info message shown when user sees / home page