Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Express 3.0 req.flash?

-- EDIT --

I wrote some middlware to do this: https://npmjs.org/package/flashify


So since the release of Express 3.0, the changes have removed req.flash()

https://github.com/visionmedia/express/wiki/Migrating-from-2.x-to-3.x (source)

So here is my question now. They have advised to use req.session.messages in a local to display a flash.

So to make a session accessible to the view, we have to do the following:

nb: In coffee-script

app.locals.use (req,res) ->
    res.locals.session = req.session

How would we access the session data from the view then clear it? We can't clear the contents of session after the view has rendered, but we can't clear it because it wont reach the view so im a bit lost as to how one would get around this problem?

like image 492
Menztrual Avatar asked Apr 17 '12 08:04

Menztrual


People also ask

When was the last time express 3x was updated?

Known and unknown security and performance issues in 3.x have not been addressed since the last update (1 August, 2015). It is highly recommended to use the latest version of Express. Creates an Express application. The express () function is a top-level function exported by the express module.

How to access uploaded files in Express 4?

In Express 4, req.files is no longer available on the req object by default. To access uploaded files on the req.files object, use multipart-handling middleware like busboy, multer , formidable , multiparty , connect-multiparty , or pez. This property holds a reference to the instance of the Express application that is using the middleware.

What is the default response type for express?

When a String is given the Content-Type is set defaulted to “text/html”: When an Array or Object is given Express will respond with the JSON representation: Finally when a Number is given without any of the previously mentioned bodies, then a response body string is assigned for you.

What is require () in express JS?

By default, Express will require () the engine based on the file extension. For example, if you try to render a “foo.pug” file, Express invokes the following internally, and caches the require () on subsequent calls to increase performance.


2 Answers

You can use the connect-flash middleware to add the req.flash() functionality back into express 3.0.

like image 89
Tim Gautier Avatar answered Oct 06 '22 03:10

Tim Gautier


I believe they simply moved req.flash to req.session.messages

like image 45
chovy Avatar answered Oct 06 '22 04:10

chovy