Last active
February 4, 2025 09:42
-
-
Save raddeus/11061808 to your computer and use it in GitHub Desktop.
Basic Express 4.0 Setup with connect-flash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require('express'); | |
var session = require('express-session'); | |
var cookieParser = require('cookie-parser'); | |
var flash = require('connect-flash'); | |
var app = express(); | |
app.use(cookieParser('secret')); | |
app.use(session({cookie: { maxAge: 60000 }})); | |
app.use(flash()); | |
app.all('/', function(req, res){ | |
req.flash('test', 'it worked'); | |
res.redirect('/test') | |
}); | |
app.all('/test', function(req, res){ | |
res.send(JSON.stringify(req.flash('test'))); | |
}); | |
app.listen(3000); | |
module.exports = app; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"dependencies": { | |
"express": "^4.0.0", | |
"express-session": "^1.0.2", | |
"cookie-parser": "^1.0.1", | |
"connect-flash": "^0.1.1" | |
} | |
} |
thinhbg
commented
Mar 21, 2020
via email
Thank you very much sir
Vào Th 6, 20 thg 3, 2020 lúc 15:30 snakehead007 <[email protected]>
đã viết:
***@***.**** commented on this gist.
------------------------------
@thinhbg <https://github.com/thinhbg> My front ent is this (in Pug using
bootstrap):
.row.justify-content-center
#messages.col-12
if messages.test
each message in messages.test
div.alert-message(class="alert alert-success alert-dismissible fade show" role="alert")=message
button(type="button" class="close" data-dismiss="alert" aria-label="Close")
span(aria-hidden="true") ×
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<https://gist.github.com/11061808#gistcomment-3220527>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AOSNHJFITXRTEDK6W7XNYH3RIMSQPANCNFSM4H5MG24Q>
.
--
Bùi Gia Thịnh
Thank you. Why does req.flash(messageName_string) return an array?
Hlw,
I am facing same error .
Have you get any solution .Please help me to get the solution .
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment