simple-flash

0.1.3 • Public • Published

simple-flash

Simple Flash is a very simple way to set flash messages in Express routes.

Installation

npm install simple-flash

Usage

In your app.js (after session setup line):

var flash = require('simple-flash');
app.use(flash());

In your route, only add your messages using the new funcion req.flash(type,message):

app.post('/foo', function(req, res){
    try {
        // your awesom code here
        req.flash('success','Your success message here!');
        res.redirect('/bar');
    } catch (e){
        req.flash('error','Your error message here!');
        res.redirect('/foo');
    }
})

For render messages in view, simpliest use the new local function flash() to return messages array.

Jade example:

for message in flash()
    .row
        .col-xs-12
            div(class="alert alert-#{message.type}") #{message.message}

Or:

- flash().forEach(function(message){
    .row
        .col-xs-12
            div(class="alert alert-#{message.type}") #{message.message}
- })

For development and tests:

git clone https://github.com/thiagobs/simple-flash.git && cd simple-flash
npm install

Run tests:

npm test

License

MIT License

Readme

Keywords

Package Sidebar

Install

npm i simple-flash

Weekly Downloads

5

Version

0.1.3

License

MIT

Last publish

Collaborators

  • thiagobs