Search code examples
sails.js

Does flash message (req.flash) exists in Sails 1.0.0 (beta)?


I was trying Sails.js beta version (1.0.0-46) and noticed that flash messages are not available out-of-box:

req.flash(type, message)

I got a TypeError: req.flash is not a function message when trying to use it.


Solution

  • Ouch... just found the answer right in the upgrade docs (Upgrading to v1.0).

    The connect-flash middleware has been removed (so req.flash() will no longer be available by default). If you wish to continue using req.flash(), run npm install --save connect-flash in your app folder and add the middleware manually.

    Run the command bellow:

    npm install --save connect-flash
    

    And modify the config/http.js file:

    middleware: {
      flash    : require('connect-flash')(),
    
      order: [
        'cookieParser',
        'session',
        'flash', // <-- add this
        // 'bodyParser',
        'compress',
        'poweredBy',
        'router',
        'www',
        'favicon',
      ],