Question

From what I understand, both do server printouts. I tried using flash below and I only see the console printout.

app.get('/', function(req, res){
    console.log('hi there!');
    req.flash('info', 'flash test');
    req.end();
});

What's flash used for and how should I be using it?

Was it helpful?

Solution

Flash messages are displayed to the user viewing your site. console.log displays on the console where server is running.

connect-flash is a middleware to implement flash messages. Flash message is displayed on the user browser, next time the user views a page. The flash is typically used in combination with redirects, ensuring that message is available to the next page that is to be rendered. It is like a reminder for last page viewed.

//go to /flash page
app.get('/flash', function(req, res){
  req.flash('info', 'Hi there!')
  res.redirect('/');
});
//info message shown when user sees / home page
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top