4

I'm trying to use express-flash in a standard web express js app. I don't want to use session, because I want to do the app as stateless as possible, but when I try to use without session, the app show me this error:

req.flash() requires sessions

Can I use express-flash without session? Can I use other alternatives for this kind of messages?

Thanks.

VC.One
  • 14,790
  • 4
  • 25
  • 57
chemitaxis
  • 13,889
  • 17
  • 74
  • 125

1 Answers1

0

Note: A flash message is a variable stored within a session that is only available once, for the next request. That is if we put a flash variable and renders a page, the flash variable is available but if we render the same (or other) page again the flash variable is not present (it is destroyed).

-- acanimal

Based on this premise, you need to have sessions to use message flashing.

One way I think you can accomplish what you want is to add an item to the request (req) object in your middleware, and then in your controller, check if the key exists. You can then pass a specific message to your template, assuming you're using a template engine or pass it as part of your response.

Hope this helps.