// This simple example shows how the express-session library works.

    // Install modules with npm install express express-session .

// Start the Express app as usual.
const express = require('express');
const app     = express();

// Import the express-session object.
const session = require('express-session');

// And invoke it with the following.
app.use(session({secret: 'secret string'}));// Please note that this is not production safe.

// Now all clients that access this app will get a cookie named connect.sid.
// It contains a unique string which identifies each client.
// The app can access this id via req.sessionID.
// Furthermore, the app can associate any value for this client via the
// req.session property.
// These values are stored by express-session and can be recalled whenever the
// client makes subsequent requests. 

app.use((req, res, next) => {
  if (!req.session.views) req.session.views = 0;
  ++req.session.views;
  next();
});

app.get('/', (req, res) => {
  res.send(`<pre>
Your session ID is ${req.sessionID} .

You have viewed this page ${req.session.views} times.
</pre>`)
});

app.listen(8000);


// https://sean.brunnock.com 12/2022