express-fm
Flash message middleware for Express and Connect.
Flash messages are messages that are displayed once when browsing on a website, usually to inform the user of success or error of an operation.
express-fm allows to set flash messages with the function req.flash
. With Express, flash messages are automatically available in locals
variable of the template thanks to an overriding of the res.render
function.
Installation
npm install express-fm
Usage
Initialization
var flash = ; app;app;
You can use many options:
app;
Options:
key | type | default | description |
---|---|---|---|
secure |
Boolean | true |
If security is disabled (false ) and middleware's called a second time, it will update flash message's options. |
wrapRender |
Boolean | true |
If set to true middleware will override res.render function for automatically make available flash messages in locals variable of the template. |
localsKey |
String | 'flash' |
The key of flash messages in locals variable of the template. |
sessionKey |
String | 'flash' |
The key of flash messages in req.session . |
Set flash messages
app;
Get flash messages
If you use Express, flash messages are automatically available in locals
variable of the template. With Jade template engine, you can display them like that:
if locals.flash each key in flash each msg in index li=msg
But you can also get flash messages manually:
app;
If middleware has overrided res.render
function, it has added him a parameters to disable the automatic sending of flash messages in the template.
Test
npm test
Release History
[20/08/2015] 1.0.2 Readme completion.
[19/08/2015] 1.0.1 res.render overriding.
[18/08/2015] 1.0.0 Initial release.