Flash Messages

Table of Contents

  1. Overview
  2. req.flash(type, message)
  3. Displaying flash messages


Flash messages allow you to send non-error messages in between HTTP requests. For example, if you want to redirect to a dashboard page upon successful submission of a form, and want to show a success message on the dashboard page.

req.flash(type, message)

Creates a message to be used in the next page view.


  • type (string or object): The type of message to be created. For example 'success'.

  • message (string): The message to send to the next page.


Returns undefined.


req.flash('success', 'The form was submitted successfully');

Displaying flash messages

Flash messages are passed to subsequent views via a messages variable.

    <% if(messages.success) { %>
        <div class="alert alert-success">
            <%= messages.success %>
    <% } %>
    <!-- other code goes here -->