Cannot read property ' Store ' of undefined Nodejs Express session

Source: Internet
Author: User

Express app configuration error when using MongoDB! "Cannot read property ' Store ' of undefined"

The main reason is the Express version 4++ problem


Settings.js

module.exports={

Cookiesecret: "xxxx",

DB: "DBName",

Host: "LocalHost",

}


App.js

var express = require ("Express");

var settings = require ("./settings");


To load Connect-mongo error notation:

var mongostore=require ("Connect-mongo") (express);

App.use (Express.session ({
Secret:Settings.cookieSecret,
Key:Settings.db,
Cookie:{maxage:1000*60*60*24*30},//30 days
Store:new Mongostore ({
Db:Settings.db
})
}));

Error after startup: Typeerror:cannot Read property ' Store ' of undefined

These are the express<4.


After Express 4.0 (including 4.0), the following wording is written:

var session = require ("express-session");

var mongostore=require ("Connect-mongo") (session);

App.use (Session ({

Secret:settings.cookieSecret,

Store:new Mongostore ({

Db:settings.db

})

});


The Package.json is configured as follows

{
"Name": "DbTest",
"Version": "0.0.1",
"Private": true,
"Scripts": {
"Start": "Node./bin/www"
},
"Dependencies": {
"Express": "~4.2.0",
"Static-favicon": "~1.0.0",
"Morgan": "~1.0.0",
"Cookie-parser": "~1.0.1",
"Body-parser": "~1.0.0",
"Debug": "~0.7.4",
"Ejs": "~0.8.5",
"MongoDB": "*",
"Connect-mongo": "*",
"Express-session": "*"
}
}


Cannot read property ' Store ' of undefined Nodejs Express session

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.