28 回复
我用的require代替的。要是用express-partials的话,在
, path = require('path')
后添上
, partials = require('express-partials')
然后在
app.set('view engine', 'ejs');
后添上
app.use(partials());
就可以用express-partials了。
collection.find(query).sort({ time: -1 }).toArray(function (err, docs) { mongodb.close(); if (err) { callback(err, null); }
var posts = [];
docs.forEach(function (doc, index) {
var post = new Post(doc.user, doc.title, doc.post, doc.time);
var now = post.time;
post.time = now.getFullYear() + "-" + (now.getUTCMonth()+1) + "-" + now.getUTCDate();
posts.push(post);
});
callback(null, posts);
});
这段代码做了什么?
app.use(function(req,res,next){
var err = req.flash('error'),
success = req.flash('success');
res.locals.user = req.session.user;
res.locals.error = err.length ? err : null;
res.locals.success = success.length ? success : null;
next();
});
弱弱的问一句,app.use(path,function,next) 三个参数是干什么的?
中间件不应该是 funciton(){ next()}这样的么?
第三个参数的next 是接受哪里的next()呀?