Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/maximilianschmitt/req-flash
Unopinionated middleware for creating flash messages of all types for Express apps.
https://github.com/maximilianschmitt/req-flash
Last synced: 2 months ago
JSON representation
Unopinionated middleware for creating flash messages of all types for Express apps.
- Host: GitHub
- URL: https://github.com/maximilianschmitt/req-flash
- Owner: maximilianschmitt
- License: mit
- Created: 2014-05-01T00:57:35.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2020-08-15T03:48:34.000Z (over 4 years ago)
- Last Synced: 2024-10-15T00:21:19.808Z (3 months ago)
- Language: JavaScript
- Homepage:
- Size: 6.84 KB
- Stars: 10
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
req-flash
=========Unopinionated middleware for creating flash messages of all types for Express apps.
## Usage
### 1. Install req-flash:
``` javascript
npm install req-flash
```### 2. Register the req-flash middleware after your session middleware:
``` javascript
var express = require('express');
var cookieParser = require('cookie-parser');
var session = require('express-session');
var flash = require('req-flash');var app = express();
app.use(cookieParser());
app.use(session({ secret: '123' }));
app.use(flash());
```**Tipp:** Use `flash({ locals: 'flash' })` to magically make all flash messages available to your views by attaching them to `res.locals['flash']` (or whatever you specifiy instead of 'flash').
### 3. Flash any amount of messages:
``` javascript
app.get('/test', function() {
req.flash('successMessage', 'You are successfully using req-flash');
req.flash('errorMessage', 'No errors, you\'re doing fine');res.redirect('/');
});app.get('/', function() {
res.send(req.flash());
});
```"/test" redirects to "/" and outputs:
```
{
"successMessage": "You are successfully using req-flash",
"errorMessage": "No errors, you're doing fine"
}
```