Created
December 26, 2019 06:16
-
-
Save abou7mied/12726c87da398dbe1119d04d41500788 to your computer and use it in GitHub Desktop.
connect-flash + hbs example
This file contains hidden or 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
const flash = require('connect-flash'); | |
const express = require('express'); | |
const hbs = require('hbs'); | |
const session = require('express-session'); | |
const cookieParser = require('cookie-parser'); | |
const app = express(); | |
app.set('view engine', 'hbs'); | |
app.use(cookieParser('keyboard cat')); | |
app.use(session({ cookie: { maxAge: 60000 } })); | |
app.use(flash()); | |
hbs.localsAsTemplateData(app); | |
app.get('/flash', function (req, res) { | |
// Set a flash message by passing the key, followed by the value, to req.flash(). | |
req.flash('info', 'Flash is back!'); | |
res.redirect('/'); | |
}); | |
app.get('/', function (req, res) { | |
res.render('index', { messages: req.flash('info') }); | |
}); | |
app.listen(3000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great simple