So my web application requires authentication, and I have a signup page where if the person tries to sign up with an email that is already in the database, I want to show th
https://gist.github.com/brianmacarthur/a4e3e0093d368aa8e423
I, too, was initially confused by flash messages in Express 4. The confusion for me arose partly from the distinction between the concept of flash messaging, a temporary message available to a template, and the various implementations of flash messaging, which include express-flash
, other modules, and custom middleware.
Just to expand on the excellent response from Thad Blankenship above, I created a Gist for the beginner that includes two approaches to flash messages--the express-flash
module and custom middleware--rendered in jade, ejs, or handlebars.
The readme includes details about the getter--req.flash(type)
--and setter--req.flash(type, message)
--methods exposed by express-flash
and how they differ from the exploitation of the res.locals
and req.session
objects exposed by express-session
in the custom middleware.