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