GitXplorerGitXplorer
t

simple-express-flash

public
0 stars
0 forks
0 issues

Commits

List of commits on branch master.
Unverified
2852bf4b8142eed14376a616f4d9e14c17895ef4

the middleware function

tthealjey committed 10 years ago
Unverified
a43ed95c1454cfda7c49f0c04bd05210f22b59a6

Create README.md

tthealjey committed 10 years ago
Unverified
3597f51606fba995a4e3ac66a2167f89e47b185b

Initial commit

tthealjey committed 10 years ago

README

The README file for this repository.

simple-express-flash

A simple ExpressJS flash middleware

This middleware adds a dead simple flash method to the request object and makes it also available inside your templates.

Install

npm i simple-express-flash --save

Configure

import express from 'express';
import session from 'express-session';
import flash from 'simple-express-flash';

express()
  .use(session({
    resave: false,
    saveUninitialized: false,
    secret: 'my keyboard cat was replaced by a dog'
  }))
  .use(flash);

And use

app.use(function (req) {
  /**
   * Store a message
   * @param {string} key
   * @param {string} message
   * @returns {string[]} a collection of set messages
   */
  req.flash('key', 'message text');
   
  /**
   * Retrieve an array of messages by key, removing them from storage
   * (such is the nature of flash messages, they disappear in a "flash")
   * @param {string} key
   * @returns {string[]}
   */
  req.flash('key');
   
  /**
   * Retrieve all messages
   * @example
   * // returns {key: ['message text']}
   * @returns {Object}
   */
  req.flash();
});

The exact same function can be used inside of your templates

each message in flash('error')
  .alert.alert-danger(role='alert')= message