Errata: June 17, 2019

Thank you for purchasing Getting MEAN with Mongo, Express, Angular, and Node, Second Edition. If you find errors not listed below, please report them in the LiveBook Errata thread. We'll update this list as necessary. Thank you!



P62, Chapter 3, Section 3.2.5 - Trying it out

Not strictly errata, but for Windows users...

For the line that states:
$ DEBUG=loc8r:* npm start
use
$ SET DEBUG=loc8r:* npm start

P124, Chapter 5, Section 5.1.2 - Creating the Mongoose connection
P127, Chapter 5, Listing 5.1

Replace the following line of code:

mongoose.connect(dbURI, { useNewUrlParser: true });

with this line:

mongoose.connect(dbURI, { useNewUrlParser: true, useCreateIndex: true});
P154, Chapter 5, Section 5.5.2 - Restoring the data to your live database

The mongorestore instruction is missing the file name that you want to restore

For the line that states:
$ mongorestore -h ds159330.mlab.com:59330 -d heroku_t0zs37gc -u heroku_t0zs37gc -p 1k3t3pgo8sb5enovqd9sk314gj dump/
change it to
$ mongorestore -h ds159330.mlab.com:59330 -d heroku_t0zs37gc -u heroku_t0zs37gc -p 1k3t3pgo8sb5enovqd9sk314gj dump/Loc8r

P168, Chapter 6, Section 6.2.1 - Specifying the request methods in the routes

Affects the e-book/livebook versions only

There's an errant space between router. and get in the line
router.get('/location', ctrlLocations.locationInfo);

It just needs removing

P176, Chapter 6, Listing 6.2

There's a missing return in the listing for the final res that appears in the code repo and should read as follows:

const locationsReadOne = (req, res) => {
    Loc
      .findById(req.params.locationid)
      .exec((err, location) => {
        if (!location) {
          return res
            .status(404)
            .json({
              "message": "location not found"
            });
        } else if (err) {
          return res
            .status(404)
            .json(err);
        }
        return res
          .status(200)
          .json(location);
       });
};
              
P178, Chapter 6, Section 6.3.2 - Adding some error trapping and putting it all together

The file name given in the explanation above Listing 6.3 is incorrect

The following listing shows the reviewsReadOne() controller in review.js (modifications in bold).
should read:
The following listing shows the reviewsReadOne() controller in reviews.js (modifications in bold).

P179, Chapter 6, Listing 6.3

Node is ignoring the initialization of the response variable because it's missing a keyword

Line 28 in the listing shows:
response = {
change it to
const response = {

P180, Chapter 6, Section 6.3.3 - Constructing a geoJSON point

Small amount of disambiguation here

For the code snippet:
const point = {
use
const near = {
instead

P194, Chapter 6, Listing 6.9

The property calls of the res object in the initial check are reversed

Lines 14 - 18:

return res
  .json(404)
  .status({
    "message": "locationid not found"
  });
should be
return res
  .status(404)
  .json({
    "message": "locationid not found"
  });

P221, Chapter 7, Listing 7.17

There is a typo in the listing title

It shows:
Creating a Jade mixin to format the dates
when it should read:
Creating a Pug mixin to format the dates

P234, Chapter 7, Listing 7.25

There is an extra (unnecessary) console.log in the listing

Remove line 10 so that the listing reads:

request(
  requestOptions,
  (err, {statusCode},{name}) => {
    if (statusCode === 201) {
      res.redirect(`/location/${locationid}`);
    } else if (statusCode === 400
        && name && name === 'ValidationError') {
      res.redirect(`/location/${locationid}/review/new?err=val`);
    } else {
      showError(req, res, statusCode);
    }
  }
);
                

P297, Chapter 9, Listing 9.19

There is an extra call to .json() that isn't needed

Line 8 is
.then(response => response.json() as Location[])
when it should be
.then(response => response as Location[])

P323, Chapter 10, Section 10.2.1 - Adding data bindings to form inputs

There is a file name typo in the text

The file namein the second paragraph is:
location-details.component.html
when it should be:
location-details.component.ts