Just beginning to touch node. js, there's a connect-flash in the process of using Express 4.x
For example, when submitting the registration information on the /reg page, the Flash method that calls the Request object req is written to the prompt message if the password that was entered two times does not match, and then the display /reg The page is removed and thrown to the view template; it looks like a Dictionary object.
This package must be referenced by the Express-session package to use why1 , and the value written will destroy the why2afterit is removed once. This is very much like the TempData object inside ASP.
The advantage of open source is to see the source code at any time ~ ~
From var msgs = This.session.flash = This.session.flash | | {}; Here it is easy to see that Flash is actually stored in the session in the key name of an object;
Then do different processing depending on the number of parameters passed in:
why1. when the incoming parameter is 2 or more, the session will have {"flash": {Key:value} Such object, key is the incoming type, value may be a string, an array or a formatted string;
Why2. When only the parameter type is passed, the corresponding value of the Flash object is removed from the session, and delete Msgs[type]is removed;
Ps:flash English explanation is: Flash I understand that the disappearance of things in a moment, very well in line with the writing intent here, but personally think that if the package name changed to "Session-flash" will be better:)
Research on using Connect-flash and its source code in Express