Magnitus (70) [Avatar] Offline
#1
Node Appendix Maybe:

Just occured to me that many readers might not be familiar with Node in addition to Express.

For example, it may not be readily apparent to some reader what __dirname means or where modules are fetched when executing require, especially with a custom module.

Also, some readers may not know how to use npm on the command line.

Maybe creating an appendix (so as not to detract from the main topic) to explain those things to total beginners might be a good idea.

Concerning Section 3.3:

I think there was a missed opportunity there to describe how to use a function generator with its arguments as closure to allow users to customize middleware.

It's hinted at earlier in the book, but never really discussed.

Also, not sure how much things changed with the latest version of Express, but I recall reading that middleware inside a app.use(UriPrefix,...) statement considers whatever comes after UriPrefix to be the root URI (in your example, "/api/users" becomes "/users" inside the middleware).

This is hinted at by looking at the code inside your middleware (ie, app.get("/users",... instead of app.get("/api/users",...), but not explicitly stated. I think it should be explicitly stated.
Magnitus (70) [Avatar] Offline
#2
Re: Pedagogical Adjustments
Almost forgot: how to make things inside a module visible externally (using exports and module.exports) would be worth discussing in a node appendix as well.
Evan Hahn (70) [Avatar] Offline
#3
Re: Pedagogical Adjustments
I agree completely! This is something I've discussed with my editors. I don't think I'll be adding a full "intro to Node" chapter, but I'm intending to add an appendix or a new section to Chapter 2 that addresses this.

With regards to the function generator comment, which example are you referring to?
Magnitus (70) [Avatar] Offline
#4
Re: Pedagogical Adjustments
In page 33, you note how cool it is logger() is a function generator. You don't elaborate on it which is fine at that point, because we are not at the point in the book where you talk about creating your own middleware.

However, in section 3.3, you start talking about how to create your own middleware and you don't use any function generator in that part.

That's fine until your reader decides to make middleware that is customisable by the end-user per URL. That's the part where function generators start to shine, because their real purpose here is that you can pass options as argument to the function generator and those arguments will live on in the returned function's closure.
Evan Hahn (70) [Avatar] Offline
#5
Re: Pedagogical Adjustments
Good point! I'll likely address that more.