闪光灯,连接闪光灯和快速闪光灯之间的区别 [英] difference between flash, connect-flash and express-flash
问题描述
我仍然对flash,connect-flash和express-flash到底有什么区别感到困惑.
I'm still kinda confused on what exactly is the difference between flash, connect-flash and express-flash.
安装:
-
flash
npm install flash
express-flash : npm install express-flash
连接闪存: npm install connect-flash
用法:
闪光灯:
app.use(session()); // session middleware
app.use(require('flash')());
app.use(function (req, res) {
// flash a message
req.flash('info', 'hello!');
next();
})
连接闪存
var flash = require('connect-flash');
var app = express();
app.configure(function() {
app.use(express.cookieParser('keyboard cat'));
app.use(express.session({ cookie: { maxAge: 60000 }}));
app.use(flash());
});
快速闪存,它甚至要求用法的设置方式应与连接闪存相同:
express-flash It even request that the usage should set up the same way you would connect-flash:
var flash = require('express-flash'),
express = require('express'),
app = express();
app.use(express.cookieParser('keyboard cat'));
app.use(express.session({ cookie: { maxAge: 60000 }}));
app.use(flash());
有人可以解释吗?
推荐答案
这三个软件包之间确实没有太大的区别.他们都以自己的方式完成同一件事.两者之间的区别是:
There really is no drastic difference between the three packages. They all accomplish the same thing in their own way. The difference between the three are:
- flash 由Express团队编写,使其成为Express的官方中间件.
- 连接闪存,如
自述文件
所述:
- flash is written by the Express team, making it an official middleware for Express.
- connect-flash as stated from the
README
:
此中间件是从Express 2.x中提取的
This middleware was extracted from Express 2.x
因此,从某种意义上说,它与 flash 类似,除了Express 2.x版本中的旧版本.但是,顾名思义,它是用于 Connect 框架的,但通常是任何 connect-*
软件包可与Express配合使用.
So in a sense this is similar to flash except a legacy version of it from Express 2.x days. However, the name suggests it was meant for the Connect framework, but usually any connect-*
packages work fine with Express.
- 快速闪存只是连接闪存的包装.您可以在源代码中此处.
- express-flash is just a wrapper around connect-flash. You can see that in the source code here.
从npm统计数据来看,
在所有这三种方法中, connect-flash
似乎是最常用的方法.
Out of all three, connect-flash
seems to be the most used judging from npm stats.
这篇关于闪光灯,连接闪光灯和快速闪光灯之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!