Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6131799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:01:22+00:00 2026-05-23T17:01:22+00:00

I have a big problem with sessions. I drive to create an application around

  • 0

I have a big problem with sessions.

I drive to create an application around “Redis” nodejs with different libraries as express.

But suddenly the sessions no longer works. And I do not understand why.
So I reformatted my server and reinstall all properly.
(I am using Debian 6)

And the basic test is still not working: (.

Here’s the test:

var express = require('express');
var app = express.createServer();

var RedisStore = require('connect-redis')(express);
app.use(express.bodyParser());
app.use(express.cookieParser());
app.use(express.session({ secret: "keyboard cat", store: new RedisStore }));

app.get('/', function(req, res){
    var sess = req.session;
    req.session.visitCount = req.session.visitCount ? req.session.visitCount + 1 : 1;

    if (sess.views) {
        res.setHeader('Content-Type', 'text/html');
        res.write('<p>views: ' + sess.views + '</p>');
        res.write('<p>expires in: ' + (sess.cookie.maxAge / 1000) + 's<p/>');
        res.write('<p>You have visited this page ' + req.session.visitCount + ' times</p>');
        res.end();
        sess.views++;
      } else {
        sess.views = 1;
        res.end('welcome to the session demo. refresh!');
      }
});

app.listen(4000);

the program runs correctly (no error).
but when I use the “sess.views” is never valid

so I always see : welcome to the session demo. refresh!

I am a bit desperate.

Thank you in advance for your help

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T17:01:23+00:00Added an answer on May 23, 2026 at 5:01 pm

    code

    I believe sess.views++ needs to be called before res.end() just like TJ’s example

    var express = require('express');
    var app = express.createServer();
    
    var RedisStore = require('connect-redis')(express);
    app.use(express.bodyParser());
    app.use(express.cookieParser());
    app.use(express.session({ secret: "keyboard cat", store: new RedisStore }));
    
    app.get('/', function(req, res){
        var sess = req.session;
        req.session.visitCount = req.session.visitCount ? req.session.visitCount + 1 : 1;
    
        if (sess.views) {
            res.setHeader('Content-Type', 'text/html');
            res.write('<p>views: ' + sess.views + '</p>');
            res.write('<p>expires in: ' + (sess.cookie.maxAge / 1000) + 's<p/>');
            res.write('<p>You have visited this page ' + req.session.visitCount + ' times</p>');
            sess.views++;
            res.end();
          } else {
            sess.views = 1;
            res.end('welcome to the session demo. refresh!');
          }
    });
    
    app.listen(4000, '127.0.0.1');
    

    packages installed

    alfred@alfred-laptop:~/database/redis-2.2.0-rc4/src$ npm ls
    /home/alfred
    ├── connect-redis@1.0.6 
    ├─┬ everyauth@0.2.15 
    │ ├─┬ connect@1.5.2 
    │ │ ├── connect-redis@1.0.6  extraneous
    │ │ ├── mime@1.2.2 
    │ │ └── qs@0.2.0 
    │ ├── oauth@0.9.2 
    │ ├── openid@0.1.8 
    │ ├── restler@0.2.1 
    │ └─┬ xml2js@0.1.9 
    │   └── sax@0.1.4 
    ├─┬ express@2.4.1 
    │ ├─┬ connect@1.5.2 
    │ │ ├── connect-redis@1.0.6  extraneous
    │ │ ├── mime@1.2.2 
    │ │ └── qs@0.2.0 
    │ ├── mime@1.2.2 
    │ └── qs@0.2.0 
    ├── hiredis@0.1.12 
    ├── jade@0.12.4 
    ├── node-expat@1.3.2 
    ├── node-stringprep@0.0.5 
    ├─┬ node-xmpp@0.2.9 
    │ └── ltx@0.0.5 
    ├── nodeunit@0.5.1 
    ├── notifo@0.0.2 
    ├── openid@0.2.0 
    ├─┬ optimist@0.2.5 
    │ └── wordwrap@0.0.1 
    ├── recaptcha@1.1.0 
    ├── redis@0.6.6 
    └─┬ socket.io@0.7.6 
      ├── policyfile@0.0.3 
      ├── redis@0.6.0 
      └── socket.io-client@0.7.3 
    

    System information

    alfred@alfred-laptop:~/database/redis-2.2.0-rc4/src$ npm -v
    1.0.15
    
    alfred@alfred-laptop:~/database/redis-2.2.0-rc4/src$ node -v
    v0.4.9
    
    alfred@alfred-laptop:~/database/redis-2.2.0-rc4/src$ cat /etc/lsb-release 
    DISTRIB_ID=Ubuntu
    DISTRIB_RELEASE=10.10
    DISTRIB_CODENAME=maverick
    DISTRIB_DESCRIPTION="Ubuntu 10.10"
    

    Curl example

    alfred@alfred-laptop:~/node/stackoverflow/6700472$ curl -c cookie http://localhost:4000/
    welcome to the session demo. refresh!alfred@alfred-laptop:~/node/stackoverflow/6700472$ curl -b cookie http://localhost:4000/
    <p>views: 1</p><p>expires in: 14396.223s<p/><p>You have visited this page 2 times</p>alfred@alfred-laptop:~/node/stackoverflow/6700472$ curl -b cookie http://localhost:4000/
    <p>views: 2</p><p>expires in: 14399.221s<p/><p>You have visited this page 3 times</p>alfred@alfred-laptop:~/node/stackoverflow/6700472$ 
    

    Works just fine!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using sqlalchemy. The question is simple, but I have a big problem, because
I have a big problem with my application and the memory. The application (java
i have a big web application running in perl CGI. It's running ok, it's
I have big problem. Lets look on the code below: protected void Application_AuthenticateRequest(object sender,
I have a big problem with my SMTP server for sending emails. It's down
I really seem to have a big problem here. I'm using MySQL to store
i have big problem with binding Stacked Column Series to my chart. I have
I have big problem because i dont uderstand properly how make my homework. Well
Hi there I have big problem with one select query There is a table:
I have a big problem. There are devices in live that send the URL

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.