This is an example of it:
// Configuration
app.configure(function(){
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(__dirname + '/public'));
});
(etc.)
app.get('/memo', function(req, res) {
console.log("index");
Memo.find({}, function(err, data) {
if(err) return next(err);
res.render('index', { memos: data });
});
});
And here is another one:
app.get('/memo/list', function(req, res, next) {
console.log("get memos");
Memo.find({}, function(err, data) {
if(err) return next(err);
res.json(data);
});
});
Taken from a simple memo pad built on node
These are the questions that are puzzling me:
- What does exactly
next/next();
do? What would happen if it is not present? - Why is the second part taking
next
as a parameter and the first isn't?
EDIT:
next
calls the next middleware insideapp.configure
? For example,bodyParser -> methodOverride -> etc
for that particularapp.get
? (Please see the additional code that I added to the top). – Graver