Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const Session = require('express-session');
- const FileStore = require('session-file-store')(Session);
- const express = require('express');
- const path = require('path');
- const app = express();
- const port = 3000;
- app.use(Session({
- store: new FileStore({
- path: path.join(__dirname, '/tmp'),
- encrypt: true
- }),
- secret: 'Super Secret !',
- resave: true,
- saveUninitialized: true,
- name: 'sessionId'
- }));
- // Access the session as req.session
- app.get('/session-in', (req, res) => {
- // Initialisation de la variable de sessions "song" avec 'be bop a lula'
- req.session.song = 'be bop a lula';
- res.send('variable song initialisé');
- });
- app.get('/session-out', (req, res) => {
- res.write('valeur de la varible song est: ' + req.session.song);
- res.end();
- });
- app.listen(port, (err) => {
- if (err) {
- throw new Error('Something bad happened...');
- }
- console.log(`Server is listening on ${port}`);
- });
Add Comment
Please, Sign In to add comment