Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First off, that website is a horrible place to go.</p> <p>Now on to the question.</p> <p><strong>What sessions actually are:</strong></p> <ul> <li>Data is stored on the server side.</li> <li>A cookie is issued which contains an ID.</li> <li>This ID gets send back to the server on every request, due to the fact that the browser sends the cookies.</li> <li>Now the server can re-associate the ID in the cookie - commonly called <code>Session ID</code> or short <code>SID</code> - with the session data stored on the server.</li> </ul> <p><a href="http://expressjs.com/guide.html#session-support" rel="noreferrer">Express.js has support for sessions built in</a>.</p> <p><strong>What the example shows:</strong></p> <ul> <li>Setting up the Express.js middleware</li> <li>Using a third-party store for saving the session data, in this case <a href="http://en.wikipedia.org/wiki/Redis_%28data_store%29" rel="noreferrer">Redis</a> (which IMO is overkill for your problem atm)</li> </ul> <p>Installing Redis requires quite some work, but it's also possible to use Express.js's built-in memory store:</p> <pre><code>var express = require('express'); var app = express.createServer(); var MemoryStore = require('connect/middleware/session/memory'); app.use(express.bodyDecoder()); app.use(express.cookieDecoder()); app.use(express.session({ store: new MemoryStore({ reapInterval: 60000 * 10 }) })); app.get('/', function(req, res){ req.session.visitCount = req.session.visitCount ? req.session.visitCount + 1 : 1; res.send('You have visited this page ' + req.session.visitCount + ' times'); }); app.listen(4000); </code></pre> <p>This will simply keep track of how many times you visited the page, closed your browser and re-opend. The counts will still be there.</p> <p>You can find more on the options of the <code>MemoryStore</code>, like maximum life time of a session, etc. <a href="http://senchalabs.github.com/connect/middleware-session-memory.html" rel="noreferrer">here</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload