My new book: Web Development with MongoDB and Node.js

Introducing my new book; Web Development with MongoDB and Node.js! Its been a long 6 months of blood sweat and tears, but its finally released!

Screen Shot 2014-10-08 at 9.07.25 PMA little over 6 months ago I was contacted by someone within Packt Publishing inquiring if I would be interested in writing a book about web development using Node.js and MongoDB. This was only a month or two after the release of my massive blog post and Amazon eBook so I was pretty excited by this opportunity! After a little bit of negotiating with the contract and fleshing out details with regard to the book description and outline, the contract was signed and I was on my way to becoming an officially published author!

The book itself is a tutorial of sorts, focusing on in-depth coverage and a hands on approach to building a complete web application from scratch using Node.js with MongoDB. Here is the chapter outline for the book:

  • Chapter 1, Welcome to JavaScript in the Full Stack, introduces you to the world
  • of full stack JavaScript development and reviews what to expect in the remainder of the book.
  • Chapter 2, Getting Up and Running, walks you through the necessary steps to download, install, and configure your development environment.
  • Chapter 3, Node and MongoDB Basics, is a brief introduction to the basics of JavaScript, Node.js, and MongoDB.
  • Chapter 4, Writing an Express.js Server, introduces you to the Express.js Node.js Web Framework and is a walkthrough of the code necessary to write the main application server.
  • Chapter 5, Dynamic HTML with Handlebars, teaches you how to create dynamic HTML
  • pages using Handlebars, the popular template-rendering engine.
  • Chapter 6, Controllers and View Models, walks you through writing the Controllers and View Models for the main application, the core of the application’s functionalities.
  • Chapter 7, Persisting Data with MongoDB, continues with our Controllers and View Models, where we wrap all of the logic using Mongoose with MongoDB as the main data layer for the application.
  • Chapter 8, Creating a RESTful API, reviews the concepts behind REST APIs and introduces the Postman REST Client tool to test and interact with our own custom Node.js API.
  • Chapter 9, Testing Your Code, introduces the tools and techniques to write automated tests for our Node.js code.
  • Chapter 10, Deploying with Cloud-based Services, is a step-by-step walkthrough of deploying your application to a number of popular cloud-based hosting services such as Heroku, Microsoft Azure, and Amazon’s AWS.
  • Chapter 11, Single Page Applications with Popular Frontend Frameworks, takes a look at the current trend in thick client applications by learning more about popular frontend single application frameworks such as Ember.js, AngularJS, and Backbone. js. Additionally, you will learn about the popular build tools frontend developers use to make their lives easier.
  • Chapter 12, Popular Node.js Web Frameworks, takes a look at some very popular and robust alternatives such as Meteor and Sails, even though Express.js is one of the most popular web frameworks for Node.

The end result after finishing the work outlined in the book is basically a working clone of an imgur.com image hosting website.

You can purchase the book online at both Amazon and PacktPub.com:

  • Amazon (physical and Kindle editions)
  • PacktPub (physical purchase includes eBook)

Proposed outline and contract negotiations

When I was first contacted about writing the book, I was basically only given a brief description and title for the book. After I said I was interested the first step was for me to put together a rough outline proposal for the book. This was pretty interesting because I was basically tasked with designing a book that needed to be 12 chapters and roughly 250 pages. Having no idea how to do this and literally no prior experience this turned out to be pretty trying. However in the end the final book came pretty close to my original proposed outline!

After the outline was accepted a contract was sent my way. There were a few very tiny conditions I wasn’t too thrilled about but my request at changes was met with no pushback whatsoever so that was pretty relieving. Once the contract was finalized I had to process some electronic paperwork with regard to wire transfer of funds (the payment was based on a schedule of meeting various milestones during the process). A schedule was also drafted and delivered to me which gave me roughly 2 weeks per chapter to deliver first draft.

Getting started and early speed bumps

The first three chapters went pretty smoothly as I got into the flow of the book. Right around the middle of chapter 3 I received revision requests for the first two chapters. This is when the idea of using Microsoft Office kicked in, unfortunately. The first three chapters I wrote using Google Docs and didn’t realize before then that the publisher uses a Word doc template with very specific styles predefined for everything. Once I received that doc I had to convert my first three chapters to it and then started using it for Chapter 4 on. Fortunately the $9.99/mo plan with Office 365 was a life saver as I really didn’t want to spend hundreds of dollars on a copy! The revisions themselves were pretty minor, only pointing out formatting issues and a few typos here or there.

Stress starts!

Up until Chapter 4, most of the writing had just been general tutorial type stuff. However Chapter 4 started the work of writing about the project that was going to be built throughout the remainder of the book. This made each chapter extra stressful as I had to not only write the tutorial web app, but also break it down and write about it line by line. Furthermore, I needed to break the app into parts that would fit into each chapter of the book. The stress here was that I was writing a web app, making sure it was written in a way that made sense in a chapter by chapter format, breaking parts of it down line by line so that I could write about it per chapter. Keeping track of all of this in my head was starting to drive me mad!

Chapter 7 was particularly grueling as I had to basically write about the bulk of the apps logic including tying everything together with MongoDB. After completing the chapter, I realized that it just became way too long and didn’t really fit in with the rest of the book. This is one of the only minor regrets I have with the book in that I would have liked to have broken chapter 7 down into 2 chapters. However the outline was made, committed to, and the flow of the book wouldn’t really make sense changing it at this point. So I forged ahead!

Rewrites and technical reviewer feedback

By the time I started writing chapter 8, I started to receive rewrite requests for chapter 1. These rewrite requests included the original chapter with changes and comments marked up based on editorial and technical reviewer feedback. Most of the feedback I received from my technical reviewers was extremely valuable and made me not only a better writer, but also stronger in the subject matter as well. The remaining chapters continued in this way, with my writing the next chapter while also receiving rewrites for earlier chapters. The work was starting to double up but the good news is that I could start to see a light at the end of the tunnel (and the majority of the hard part was over as the app I was writing about was complete).

It was also during this time that I was tasked with selecting an image for the cover of the book as well as providing the bullet points and back of book description. In addition I needed to provide an author’s bio and the technical reviewers submitted their bios as well.

Sprint to the finish

Once I delivered the final chapter, I received “prefinal” copies of each chapter which was a PDF of the chapter formatted exactly how it would appear in the book along with all of the changes made during the rewrite and technical feedback process. This is when I started to get excited because I was finally seeing the result of all of the hard work – these prefinal chapters really started to look like a finished product! Reviewing the prefinal chapters was easy because it only involved my reading the chapter again and just looking for anything major that popped out and/or was missed during the rewrite process. The changes I actually submitted for each of these chapters was very very minor.

Shortly after the last prefinal chapter was handed off, I received notice that the book was published!

All done!

So, after about 6 months from original outline proposal to final digital copy of the book sent to the printer, I received my 3 physical copies of the book! It was a hard hard process, with a lot of work and a lot of late nights plugging away on chapters and rewrites. There were times when I thought the project would never be finished and times when I wondered if it was even worth it and if I’d ever write again. For me physically receiving a copy of the book was extremely exciting and made the whole process very rewarding!

I learned so much writing this book and honestly, I would definitely do it again for sure!

21 thoughts on “My new book: Web Development with MongoDB and Node.js

  1. When trying out the code in the book, I get an error that connect has no method json, even though I am using express 3.5.1 as you suggested. I had to add connect myself: ‘npm install connect –save’ as it seems this doesn’t get installed with express 3.5 automatically. Maybe it’s worth mentioning this in an addendum to the book, since more people will probably get stuck on this.

    Like

  2. Hi Jason. When trying to run the code at the beginning of chapter 7, on test.js (pg 121 on the digital edition) for the insertion of records into mongo, i’m getting a process.nextTick error. Also, instead of getting the number of records inserted, I’m getting an undefined. Any idea as to what this might be?
    Thanks

    Like

  3. I’ve been struggling for many days with the “SaveImage()” function in Chapter 6 in uploading Images. The input form returns a multi-part req. Body-parser doesn’t seem to parse it. I get an undefined req.files. (in the Image.js file in the create function SaveImage.)

    It seems that the confusion is in the switch of middleware in Express. I’ve tried multer(), busboy(), and others, but none seem to produce a req.files in response to that form submission.

    Is there any middleware that works with Express3.5 and parses multi-part forms ? Or, how do you handle the multipart form and files?

    Thanks in advance.

    Like

    • Hi Jim,

      Sorry to hear about your struggles. First of all I want to point you to this code repo: https://github.com/shorttompkins/nodebook which has all of the code from the book, and is the latest version. All of the code in that repo is working so that might help get you situated before I can investigate a little more and respond with greater detail.

      Like

      • Thanks for the quick response! In your updated code files, you are using ‘connect’ middleware. That doesn’t seem to be even possible anymore, even when using Express 3.5. (or, am I wrong?) So, I ended up using Express 3.5 and the new middleware you describe on page 72 (morgan, body-parser, etc).

        I don’t really want to ask you to debug this “mix” of middleware. But, I’m trying to get to something that I can use to get through the rest of your book. I chose not to go to Express 4.0, because of your note that said you will use 3.5 for the rest of the book. However, ‘connect’ doesn’t seem to even be possible any more.

        And, as a result, my server is not parsing the form correctly, and not able to interpret the line var tempPath = req.files.file.path in images.js.

        By the way, I really enjoyed the first 5 chapters of your book, and they taught me quite a bit. This middleware problem in chapter 6 has now taught me that I don’t know as much as I thought I did…

        Like

      • Yeah at this point, considering the age of the book, I think it would be best to try to revist the last part of Chapter 4 that talks about using Express 4. As well as some of the documentation on the new middleware that Express suggests using. You can take a look at another repo I have that should help with some of that stuff: https://github.com/shorttompkins/benm

        Like

  4. This is one of my favorite coding books ever. I’ve spent something like a year and a half trying to learn Node and I’ve bought a handful of other books that didn’t quite do it. I come from a PHP and client side JavaScript background, so I understood server side principles and JavaScript well, but I had a hard time with Node. This book makes Node and Express’s unique stumbling blocks perfectly clear, and even makes me realize that they’re cool features, not annoying things I just have to learn. For example, I pretty much never understood middleware until this book, which summed it up in a perfect little paragraph. After a year and a half of confusion! I’m forever grateful; thanks so much for teaching such a powerful and complex tool in such a simple and clear format.

    And you did a great job breaking the app into chapters, so the hard work is definitely appreciated. Other books fail to do that and try to get you testing and using Grunt and setting up all sorts of tools before you even understand what it is you’re building, which throws me off. I like that you go piece by piece, concept by concept, so that I understand exactly what I’m learning and, just as importantly, why it’s valuable. Thanks, and I look forward to reading other tutorials you write.

    Liked by 1 person

  5. Hi Jason,

    Just want to say I love the book. I got around all the issues in the book and have my little imgploader working perfectly and now on Chapter 8 with learning how to do RESTful API. I really like how organized, how you layout the project, how you start with sample data first, then move to using the models, OO thinking, and patterns you do in the book. You are well read, completely understandable, and a very enjoyable read. You should do another book where you do add User Authentication using passport.js and etc or put it as a blog on your website as an addendum 🙂

    I plan to make my website http://www.killerssoftware.com and make it dynamic using node at some point. Currently trying to help out a startup with website/web services and iPhone/iPad development.

    Thanks,

    Kenneth

    Like

    • Thanks so much for the awesome feedback! Funny you should mention that… Im actually hard at work on my next book – which is going to take the format of this book and expand apon it (starting from scratch again) quite a bit. This will include building out the entire backend using node and mongo, but this time wrapping the entire frontend with a React app. The app will use Passport for full authentication, and a lot of coverage on the build tools and process as well. I also hope to accompany each chapter with a screencast. Im going to self-publish the book using a “pay what you want” model as well 😉 Thanks again!!

      Like

  6. Jason,

    Where is the full source for the spy code in Chapter 9. I am trying to setup a test where you talk about spying on sum but unable to get it correct. Can you post that here or give me the link to the source so I can look at it.

    Kenneth

    Like

  7. Thanks, I ended up unit testing all the GET calls for the one test app that gets from imdb, external-api from Chapter 8 but using supertest instead 😉 Not so sure I like spy and stubs yet.

    Like

    • That might work for your external API calls, but eventually youre going to have a method that calls another method, and then youre basically going to HAVE to use a Spy. So better get used to it now 😉

      Like

  8. Ok, now I like the spies and stub’s now that your later pages of Chapter 9 shows complete unit testing of the imgploader app. When you first start talking about “Spies and stubs with Sinon.js” you don’t provide full working examples like you do for just about the entire book so it wasn’t as clearly understood.

    Like

  9. Hey Jason — I am going through the first edition of your book, Web Development with MongoDB and NodeJS, and I am getting some errors in Chapter 4:

    superdata-6:imgpload vb$ node server.js
    module.js:338
    throw err;
    ^
    Error: Cannot find module ‘connect’
    at Function.Module._resolveFilename (module.js:336:15)
    at Function.Module._load (module.js:278:25)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object. (/Users/vb/Hacks/NodeJS/imgpload/server/configure.js:1:77)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)

    I read on Amazon that we need to install the Connect module in the root directory of the app, i.e., npm install connect@2.14.1 –save
    Is that correct? I couldn’t find an errata page for the book.

    Like

    • Yes that is correct. Sorry for that. I’m pretty sure that was fixed in the 2nd ed of the book but again my apologies for the inconvenience. If you have any other issues you can check the full source code available on my github.

      Like

  10. I just read first five chapters. It is a excellent book for a new node.js developer as me. I did a small change for Chapter 4 configure.js to make it work:
    Use routes.initialize(app); instead of routes(app);
    Also use npm to install a few modules include ‘connect’

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s