458806 (2) [Avatar] Offline
To anybody having trouble with Express in Action: Chapter 8,

The example program in Express in Action: Chapter 8 was not working for me, initially. However, I managed to get it working with a bit of tinkering! I thought I would share what I did, in case others are having trouble.

For starters, I added C:\Program Files\MongoDB\Server\3.4\bin to my environmental path variable in Windows, so I could just enter mongod in a command prompt window and then mongo in a second command prompt window to get my MongoDB working on local port 27017. Explaining how to do this in detail might be a good thing to go over in the book!

For Express in Action: Chapter 8, your Express app won't work until you finish at least all of the code up until Listing 8.28, on page 142. This confused the heck out of me when I first read this chapter! The author really needs to make this crystal-clear to first-time readers at the beginning of Express in Action: Chapter 8!

Once you have your Express app coded up to this point, you need to open a third command prompt window and enter npm start to get your Express app working and running on local port 3000. Then, you just need to visit local port 3000 in a browser of your choice to use your Express app. Explaining how to do this in detail might also be a good thing to go over in the book!

Also, there is a problem at the end of Express in Action: Chapter 8, too. I fixed it though! Here is what I changed for Listing 8.32 POST /edit (in routes.js) in Express in Action: Chapter 8:

Note: Code on top is new and good code from my brain and code on bottom is old / bad code from the textbook.

// now working! :D
// new code from my brain: 
router.post("/edit", ensureAuthenticated, function(req, res) {
	var userID = req.user._id;
	var newDisplayName = req.body.displayname;
	var newBio = req.body.bio;
	User.update({ _id: userID }, { $set: { displayName: newDisplayName, bio: newBio }}).exec();
	req.flash("info", "Profile updated!");

// old code from textbook (not working):
router.post("/edit", ensureAuthenticated, function(req, res, next) {
  req.user.displayName = req.body.displayname;
  req.user.bio = req.body.bio;
  req.user.save(function(err) {
    if (err) {
    req.flash("info", "Profile updated!");

PS: I hope all of this helps somebody!

PPS: I wish the book Express in Action covered more of MySQL and how it works with Sequelize (see page 121, just above Section 8.1.1, of Express in Action: Chapter 8).

PPPS: Other than these points, I am loving this book! smilie

Andrew Nash
University Student
Evan Hahn (66) [Avatar] Offline
You're totally right—there are a few errors in Chapter 8. I've noted them and I hope I can release a new edition at some point.

Hope the rest of the book is helpful!
458806 (2) [Avatar] Offline
Dear Evan Hahn,

Thanks for the reply! I have to say, I thoroughly enjoyed reading your book! I think you could expand this book into a whole book series!

If you wouldn't mind, I have a few suggestions, from a reader's perspective, that I would like to make.

It is a much more enjoyable read and learning experience when a writer and educator moves at a slower pace. This allows all topics to be absorbed thoroughly and allows for reflection, which is very important. The last part of the book was at warp speed, for example. There could be some changes made here and, possibly, room for expansion.

In fact, you could expand a lot things in the book. However, the last parts especially could be expanded into a bunch of separate books. This could lead to an entire series of books on NodeJS, Express and their supporting technologies. I am not sure if this is something that you would be interested in doing, however.

When learning, I really enjoy building full apps. I think a lot of people would agree with me here. So, I think in the future a good strategy for writing would be to focus each chapter into designing its own unique app. That way, each chapter reads from start to finish and at the end the reader has a sweet new app that they built! Plus, they learned something new! I would leave combining apps for the reader to figure out. That way, everything in the book stays separate and nice and organized.

The best part of writing a book this way is that you can reorganize chapters and it won't really effect things that much, since each chapter is modular.

I hope this helps! I am looking forward to more of your work!

Andrew Nash
Evan Hahn (66) [Avatar] Offline
I like the suggestion! I'll think on it.