【发布时间】:2019-02-25 10:24:47
【问题描述】:
谁能告诉我我的代码有什么错误。我找不到我的错误_________________________________________________________________________
router.get('/:filename', (req,res) => {
const img = req.params.filename; // Filename
gfs.collection('wdress').findOne({filename: img}, (req,file) => {
if(req.session.name==null) {
req.session.name = [{
brand: img
}]
} else {
req.session.name.push({
brand: img
});
}
});
});
错误
TypeError: Cannot read property 'session' of null
at gfs.collection.findOne (M:\FinalProject\Commerce\routes\index.js:186:8)
at result
(M:\FinalProject\Commerce\node_modules\mongodb\lib\utils.js:414:17)
app.js
app.use(function(req, res, next) {
res.locals.items = req.session;
next();
});
【问题讨论】:
-
是的,我已经初始化了那些: