node.jsmongodbsessionconnect-mongo

Node.js, Session with infinite loop


I'm using expressjs and connect-mongo@0.1.7 as the MongoStore for session.

What happen is, the session code was working. but after I upgrade node and npm to the latest version, and Mongo to 2.0.2, then if I put express.session ( store:new MongoStore) then it will run a infinite loop. Any idea what's happening?

here is my code:

express.createServer(
  express.cookieParser(),
  express.bodyParser(),
  express.session({ secret: cfg.session_secret,
  cookie: { domain: 'mydomain.com' },
  store:new MongoStore({

    db: cfg.db_session_name,
    host: cfg.db_ip,
    port: cfg.db_port
    })
  })
)

Here is the error:

TypeError: Not a string or buffer
at Object.createHmac (crypto.js:129:21)
at Object.sign (/node_modules/connect-mongo/node_modules/connect/lib/utils.js:135:6)
at Object.serialize (/node_modules/connect-mongo/node_modules/connect/lib/middleware/session/cookie.js:115:17)
at ServerResponse.writeHead (/node_modules/express/node_modules/connect/lib/middleware/session.js:265:46)
at ServerResponse._implicitHeader (http.js:808:8)
at ServerResponse.end (http.js:645:10)
at next (/node_modules/express/node_modules/connect/lib/http.js:167:13)
at pass (/node_modules/express/lib/router/index.js:219:24)
at nextRoute (/node_modules/express/lib/router/index.js:209:7)
at callbacks (/node_modules/express/lib/router/index.js:274:11)

Solution

  • Just got the temp solution for that. from another noder "jacobstr"

    see this: https://github.com/kcbanner/connect-mongo/issues/29#issuecomment-4233108

    So, I go to node_modules/connect-mongo folder. Edit the package.json like that: https://github.com/jacobstr/connect-mongo/blob/master/package.json (only one change: <2 ).

    Then in that folder, run sudo npm install -d

    then everything works. :)