npm install server-connect.io1- Create a new Express application and set up sessions:
const express = require('express');
const session = require('express-session');
const flash = require('server-connect.io');
const app = express();
app.use(session({ secret: 'keyboard cat', resave: false, saveUninitialized: true }));
app.use(flash());
app.use(flash.clearFlash());
app.get('/', (req, res) => {
req.flash('info', 'Welcome!');
res.send(req.flash('info'));
});
app.listen(3000, () => {
console.log('Server started on http://localhost:3000');
});2- Using flash messages in routes:
app.get('/', (req, res) => {
req.flash('info', 'Welcome!');
res.send(req.flash('info'));
});
app.listen(3000, () => {
console.log('Server started on http://localhost:3000');
});# Flash Function The req.flash function is added to the request object. It can be used to set or get flash messages.
Setting a flash message
req.flash(type, msg);## Instalação
npm install server-connect.io1- Create a new Express application and set up sessions:
const express = require('express');
const session = require('express-session');
const flash = require('server-connect.io');
const app = express();
app.use(session({ secret: 'keyboard cat', resave: false, saveUninitialized: true }));
app.use(flash());
app.use(flash.clearFlash());
app.get('/', (req, res) => {
req.flash('info', 'Welcome!');
res.send(req.flash('info'));
});
app.listen(3000, () => {
console.log('Server started on http://localhost:3000');
});2- Using flash messages in routes:
app.get('/', (req, res) => {
req.flash('info', 'Welcome!');
res.send(req.flash('info'));
});
app.listen(3000, () => {
console.log('Server started on http://localhost:3000');
});# Flash Function The req.flash function is added to the request object. It can be used to set or get flash messages.
Setting a flash message
req.flash(type, msg);