michaeldeMacBook-Pro:blog michael$ node app
express-session deprecated undefined resave option; provide resave option app.js:24:9
express-session deprecated undefined saveUninitialized option; provide saveUninitialized option app.js:24:9
Express server listening on port 3000
/Users/michael/blog/node_modules/mongodb/lib/mongodb/connection/base.js:246
throw message;
^
TypeError: Cannot read property 'length' of undefined
at processResults (/Users/michael/blog/node_modules/mongodb/lib/mongodb/db.js:1603:31)
at /Users/michael/blog/node_modules/mongodb/lib/mongodb/db.js:1641:20
at /Users/michael/blog/node_modules/mongodb/lib/mongodb/db.js:1179:7
at /Users/michael/blog/node_modules/mongodb/lib/mongodb/db.js:1912:9
at Server.Base._callHandler (/Users/michael/blog/node_modules/mongodb/lib/mongodb/connection/base.js:448:41)
at /Users/michael/blog/node_modules/mongodb/lib/mongodb/connection/server.js:481:18
at MongoReply.parseBody (/Users/michael/blog/node_modules/mongodb/lib/mongodb/responses/mongo_reply.js:68:5)
at null.<anonymous> (/Users/michael/blog/node_modules/mongodb/lib/mongodb/connection/server.js:439:20)
at emit (events.js:107:17)
at null.<anonymous> (/Users/michael/blog/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:201:13)
到了注册这一步就遇到这样的问题 不知道如何解决
@qianjiahao app.get('/reg’,function(req,res){ res.render('reg’,{ title: '注册’, /user: req.session.user, success: req.flash(‘success’).toString(), error: req.flash(‘error’).toString()/ }); });
//app.post('/reg',checkNotLogin);
app.post('/reg',function(req, res){
var name = req.body.name,
password = req.body.password,
password_re = req.body['password_repeat'];
if(password_re != password){
req.flash('error','两次输入的密码不一致!');
return res.redirect('/reg');
}
var md5 = crypto.createHash('md5'),
password = md5.update(req.body.password).digest('hex');
var newUser = new User({
name: name,
password: password,
email:req.body.email
});
User.get(newUser.name,function(err,user){
if(user){
req.flash('error','用户已存在!');
return res.redirect('/reg');
}
newUser.save(function(err,user){
if(err){
req.flash('error',err);
return res.redirect('/reg');
}
req.session.user = user;
req.flash('success','注册成功!');
res.redirect('/');
});
});
});
前面的提示应该是你的session设置有问题,可以这样
app.use(session({
secret: setting.cookieSecret,
store: new MongoStore({
db: setting.db,
}),
resave: true,
saveUninitialized: true
}));
我遇到了同样的问题搞了很久,是模块的版本没对上 { "name": "N-blog", "version": "1.0.0", "private": true, "description": "N-blog for express4.x", "scripts": { "start": “node app” }, "dependencies": { "express": "4.10.2", "body-parser": "1.9.0", "cookie-parser": "1.3.3", "morgan": "1.3.1", "serve-favicon": "2.1.5", "ejs": "1.0.0", "markdown": "0.5.0", "mongodb": "1.4.15", "express-session": "1.9.1", "connect-flash": "0.1.1", "connect-mongo": "0.4.1", "multer": “0.1.6” } } 把package.json换成这个试试