Flash messages to use with ExpressJs
Switch branches/tags
Nothing to show
Failed to load latest commit information.
lib Fix error for removing message Oct 14, 2013
.gitignore Initial commit Apr 12, 2013
LICENSE Initial code Apr 12, 2013
README.md Version 0.0.3 Aug 1, 2013
index.js Initial code Apr 12, 2013
package.json Fix error for removing message Oct 14, 2013



Flash messages support to use with ExpressJs.


npm install flash-messages


var FlashMessages = require('flash-messages');




Configuration is not mandatory but allows to specify if the module should activate the debug and verbose mode as well as the field name in the locals to contain the flash messages. Default configuration is debug: false, verbose: false and fieldName: flash.


  debug: false,
  verbose: false,
  fieldName: messages


The initialisation has to be done after the session activation in express application.



The method flash is added to the express request object. this method if no parameter is given, list all the messages present in the flash messages.

// return list of messages

If a string parameter is given, it retrieves the message with the key equals to the string argument, and if the message has a scope equal to REQUEST_SCOPE then the message is removed from the flash messages.

// return MESSAGE { key: 'error_login', value: ..., scope: ... }

If the method is called with one object argument or an array of object as argument, a message or a list of messages are created and stored in the flash messages. These objects have to declare a key, and a value. They can also declare a scope: FlashMessages.REQUEST_SCOPE / FlashMessages.SESSION_SCOPE. By default the REQUEST_SCOPE scope is set and force the message to be pull out of the flash messages if requested. The SESSION_SCOPE scope mode keeps the message in the flash messages until the session is deleted; this message can be updated by adding a new message with the same key to the flash messages.

  { key: 'error_login', value: 'Wrong Login/Password' },
  { key: 'username', value: 'test', scope: FlashMessages.SESSION_SCOPE }];
// 2 messages are added to the flash messages, one containing the login error message
// and the other one containing the username used (this username will be keeped until
// the session in deleted, meaning if you refresh, the error login message will not
// exists anymore but the username will)

If you pass 2 or 3 arguments then a message will be created with for key the first argument, for value the second one and for scope the third (not mandatory) one.

req.flash('username', 'test', FlashMessages.REQUEST_SCOPE);

The method flashBody is also added to flash all body data.