Coder Social home page Coder Social logo

flashify's Introduction

Flashify

Flash notifications for Express 3 applications

Installation

Firstly install the module via npm:

npm install flashify

Then require it into your application:

var flashify = require('flashify');

Then tell Express to use the middleware in your configuration function BEFORE app.router :

app.use(express.cookieParser('secret'));
app.use(express.session());
app.use(flashify);
app.use(app.router);

Usage

Flashify binds itself to your request object so you can easily set a flash notification by the following:

app.get('/secret', function(req,res){
  req.flash('Sorry, go away');
  res.redirect('/');
});

To send a flash notification in the same route with out redirecting, you can do the by using res.flash

app.get('/secret', function(req,res){
  if (req.session.isAdmin)
  {
    res.flash('info','You are an awesome admin because you use flashify');
    res.render('secret/page');
  }
  else 
  {
    req.flash('Sorry, go away');
    res.redirect('/');
  }
});

Inside your view, you can loop through and get the flash by the following (Example in Jade):

if (flash.message != undefined)
  li= flash.message

Custom Types and Multiples

You can queue up multiple flash messages with custom types using the same methods as above:

app.get('/secret', function(req,res){
  req.flash('error', 'Some silly error');
  req.flash('error', 'Some other silly error');
  req.flash('this still queues up as well!')
  req.flash('error', 'Some other other silly error');
  res.redirect('/');
});

flashify's People

Contributors

fampinheiro avatar meeech avatar robertkowalski avatar scarvell avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

flashify's Issues

Error on redirect

I get the following error when using:
req.flash('info', 'You are an awesome admin because you use flashify');
return res.redirect("/");

/Users/peili/node_modules/meeting/node_modules/mongoose/lib/utils.js:413
throw err;
^
TypeError: Object function (e) {
var t, _ref;
if ((t = this.indexOf(e)) > -1) {
return ([].splice.apply(this, [t, t - t + 1].concat(_ref = [])), _ref);
}
} has no method 'forEach'
at ServerResponse.res.redirect (/Users/peili/node_modules/meeting/node_modules/flashify/lib/flashify.js:80:32)
at Promise.module.exports.app.post.passport.authenticate.failureRedirect (/Users/peili/node_modules/meeting/src/auth.js:202:22)

Thanks!

I couldn't get connect-flash to work but your flashify works great!!! Close this 'issue' anytime, just letting you know I'm thankful

Express 4/Feathers support

Is this module supposed to work with Express 4 or Feathers.js by default? Or do I need to do something more. I'm using Handlebars as well, if that helps.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.