Research on using Connect-flash and its source code in Express

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.