Guest User

Untitled

a guest
Dec 10th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  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. });
Add Comment
Please, Sign In to add comment