daily pastebin goal
57%
SHARE
TWEET

Untitled

a guest Dec 10th, 2018 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const Session = require('express-session');
  2. const FileStore = require('session-file-store')(Session);
  3. const express = require('express');
  4. const path = require('path');
  5. const app = express();
  6. const port = 3000;
  7.  
  8. app.use(Session({
  9.     store: new FileStore({
  10.         path: path.join(__dirname, '/tmp'),
  11.         encrypt: true
  12.     }),
  13.     secret: 'Super Secret !',
  14.     resave: true,
  15.     saveUninitialized: true,
  16.     name: 'sessionId'
  17. }));
  18.  
  19.  
  20. // Access the session as req.session
  21. app.get('/session-in', (req, res) => {
  22.     // Initialisation de la variable de sessions "song" avec 'be bop a lula'
  23.     req.session.song = 'be bop a lula';
  24.     res.send('variable song initialis√©');
  25. });
  26.  
  27. app.get('/session-out', (req, res) => {
  28.     res.write('valeur de la varible song est: ' + req.session.song);
  29.     res.end();
  30. });
  31.  
  32. app.listen(port, (err) => {
  33.     if (err) {
  34.         throw new Error('Something bad happened...');
  35.     }
  36.  
  37.     console.log(`Server is listening on ${port}`);
  38. });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top