npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

expressjs-flash

v1.0.0

Published

Flash message middleware for Connect.

Downloads

23

Readme

ExpressJS-Flash

The flash is a special area of the session used for storing messages. Messages are written to the flash and cleared after being displayed to the user. The flash is typically used in combination with redirects, ensuring that the message is available to the next page that is to be rendered.

This is inspired by connect-flash module used for ExpressJS>=3.x.

But I felt that the connect-flash was too basic. I made a new module to include some more features that I felt were sorely needed for many workflows.

Install

$ npm install connect-flash

Usage

Express

Flash messages are stored in the session. First, setup sessions as usual by enabling cookieParser and session middleware. Then, use flash middleware provided by connect-flash.

var flash = require('connect-flash');
var app = express();

app.configure(function() {
  app.use(express.session({ 
    secret: 'keyboard cat',
    cookie: { maxAge: 60000 }
  }));
  app.use(flash());
});

Options for Middleware

You can pass options to the middleware.

  app.use(flash({
    passToView : true  //This enables you to use the getFlash() and setFlash() in the view directly, Default: true
  }));
});

With the flash middleware in place, all requests will have a req.getFlash() and a req.getFlash() function that can be used for flash messages.

app.get('/flash', function(req, res){
  // Set a flash message by passing the key, followed by the value, to req.flash().
  req.setFlash('info', 'Flash is here!');
  res.redirect('/');
});

app.get('/', function(req, res){
  messages=req.getFlash('info');
  res.render('index', { messages: req.getFlash('info') });
});

Options for the functions

You can pass options to the get and set functions

app.get('/flash', function(req, res){
  // Set a flash message by passing the key, followed by the value, to req.flash().
  req.setFlash('info', 'Flash is back!',{
    maxReads: 4,   //The number of times this message can be read, default: 1
    reqCount: 8    //The number of requests through which this message persists, default: null, This means that the middleware does not keep track of this. Note: a redirect counts as a request and decreases this counter
  });
  res.redirect('/');
});

app.get('/', function(req, res){
  messages=req.getFlash('info',{
    reflash: true, //This stops it being counted as a read, Useful when needing to read in a middleware
  });
  res.render('index', { messages: req.getFlash('info') });
});

Examples

For an example using connect-flash in an Express app, refer to the express3 example.

Feature Requests and Contributions

If you want a Feature to be added to this module, you can either open an issue or contribute yourself to the package on dev branch

Tests

$ npm install --dev
$ make test

Credits

License

The MIT License

Copyright (c) 2012-2013 Vaibhav Agarwal