I'm pretty much a Node.js beginner and an Express newbie. I've been spending the last few days reading tutorials on Express and Node.js development. Today, I came across some tutorials by Azat Mardanov. They were very informative and seemed well written. So, I bought the "Beginner" version of the Express.js Guide.
As with the tutorials, the book is very well written. Right now, I'm going through page by page to fill in the gaps of my Express.js knowledge (basically huge holes). I just saw something in the book that I think is a typo. However, I can't find any way to notify the author about it. The book's website doesn't have a comments section or forum. So, I'll post the issue here and reach out via Twitter.
In Chapter 15 discussing Routing, there are several examples including middleware when handling app VERBS. Azat mentions
Another useful technique is to pass callbacks as items of an array, thanks to the inner workings of arguments JavaScript mechanism3:
Here is the sample code provided:
var authAdmin = function(req,res,next){ ...
}
var getUsers = function(req,res,next){
...
return next();
return next();
}
var renderUsers = function(req,res){
}
var admin = [ authAdmin, getUsers, renderUsers ];
app.get('/admin', authAdmin, getUsers, renderUsers);
Oddly, the app.get(....)
section is identical to the previous section in the book BEFORE defining the variable admin
.
I THINK the correct code should be :
var authAdmin = function(req,res,next){ ...
}
var getUsers = function(req,res,next){
...
return next();
return next();
}
var renderUsers = function(req,res){
}
var admin = [ authAdmin, getUsers, renderUsers ];
app.get('/admin', admin);
In the "corrected" code, the admin
array is passed in as the callbacks for app.get()
.
Is this correct?