Skip to content

guio11221/server-connect.io

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Instalação

 npm install server-connect.io

Demonstração

1- 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);
  • type (string):
  • The type of the message (e.g., 'info', 'error').
  • msg (string | array):
  • The message or an array of messages to flash.
    ## Instalação
     npm install server-connect.io

    Demonstração

    1- 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);
  • type (string):
  • The type of the message (e.g., 'info', 'error').
  • msg (string | array):
  • The message or an array of messages to flash.

    Releases

    No releases published

    Packages

    No packages published