Errata for the book "Smashing Node.js" by Guillermo Rauch
first edition, 2012

This is an excellent book! However, it contains a large number of mostly minor typos and errors. I have submitted all of these to the publisher, Wiley. Before submitting them, I asked why none were posted on their site. They told me it was because they hadn't received any. I find that hard to believe.

Months after submitting all of these, there is still no official errata for the book. This is not the authors fault. I sent the same list to him and he thanked me for doing so.

I teach a class on Node.js and the students all get a copy of this book. They need an errata so I decided to just publish it myself.

If you would like to contribute additional items to this errata, email them to r.mark.volkmann@gmail.com.

Chapter 2

"Function Arity" p. 19

The function "a" needs a body to be valid syntax.

"Closures" p. 19

The line "a == 3" at the bottom of the page is first statement in the book to not end with a semicolon. Most statements in the book do, but a significant number do not. It would be good to address this or be consistent.

"Inheritance" p. 21

if (false !== a) return;
should be
if (false === a) return;

"Array Methods" p. 23

From Yihang Ho ...
In the code after "To filter elements",
[1, 2, 3].forEach(function (v) {
should be
[1, 2, 3].filter(function (v) {

Chapter 3

"Stack Traces" p. 37 1st paragraph

It says "in future versions of Node, machinery will". Mention that the machinery is "domains".

Chapter 4

"Useful Globals" p. 40 3rd paragraph

"An example of this is a the setImmediate API" should be "An example of this is the setImmediate API"

"Useful Globals" p. 40 3rd paragraph

Add "and setImmediate" to the end of the last sentence.

"Events" p. 46 2nd paragraph

Change "process.EventEmitter" to "events.EventEmitter".

Chapter 5

"Sync or Async?" p. 54

Near the middle of the page "__dirname" is used for the first time, but it is not described until page 64.

"Sync or Async?" p. 54

After the first screenshot on the page, change "The approach" to "The next approach".

"Input and Output" p. 57

After call to "process.stdin.resume();" add "process.stdin.setEncoding('utf8');"

"Interacting with the FS" p. 63

On the first code line, it may be preferred to use "parseInt(data)" instead of "Number(data)".

"Watch" p. 68

Change the regular express from /\.css/ to /\.css$/

Chapter 6

"Telnet" p. 72

In the paragraph before the second screenshot, change "node server.js" to "node web-server.js".

"Understanding the net.server API" p. 75

In the last paragraph, change "callback passes" to "callback is passed".

"Receiving Connections" p. 77

I cannot get alt+[ (or option+[) to end a telnet connection on a Mac, but ctrl+] works on a Mac.

"Testing with a Real-World IRC Server" p. 85

A screen shot is missing. In its place is some syntax that supposedly refers to it.

Chapter 7

"Connections" p. 94 2nd paragraph

Change "connections to a same" to "connections to the same".

"Printing Out the Form" p. 96

It says "You can try pressing Enter." Doesn't the button have to be marked as submit button for this work? Even if it is, doesn't the button have to have focus?

"Putting the Pieces Together" p. 102

Change "the querystring parse module" to "the querystring parse method".

"Sending a Body of Data" p. 107

The second line of code contains two statements. The author probably intended to put those on separate lines.

"Getting Tweets" p. 107

I think the public search API for Twitter now requires the use of OAuth. If that's true, none of the Twitter examples in the book work now.

"Getting Tweets" p. 109 2nd paragraph

Change "fairly uncommon" to "fairly common".

Chapter 8

"A Simple Website with HTTP" p. 117 last paragraph

It says "If an error occurs, you abort the process and send the HTTP status code 404 ...". This is not a good status to send for errors.

"A Simple Website With Connect" p. 120

Change "npm install" to "npn install connect".

"Body Parse" p. 134

Remove the duplicate <input> tag in the first code example.

"BasicAuth" p. 142

Why isn't the basicAuth middleware registered like other middleware with server.use? The example requires a person to interactively approve or deny each user. It would be a better, more realistic example if it compared to users and passwords in a file or databases.

Chapter 9

"Setup" p. 147

The API for Express has changed. Change "var app = express.createServer();" to "var app = express();" This same change is needed in several pages that follow.

"Setup" p. 148 1st paragraph

Change "just one flag" to "just an option name".

"Defining Routes" p. 150

In the paragraph that starts with "Notice", after "search function," add "to its callback".

"Defining Routes" p. 150

In the paragraph that starts with "In this route", change "tweets" to "results".

"Search" p. 151

In the second code block, the name of the callback function is "fn". It seems much more common in Node to name this "cb". In this same code block, the callback function passed to "end" should check the HTTP status code for an error.

"Search" p. 151

The statement that it's smarter to ask whether an array of tweets was received instead of checking the status code seems questionable.

"Settings" p. 153

The commands "NODE_ENV=production" and "node server" are combined on one line without a semicolon between them.

"Settings" p. 153

Change "If node NODE_ENV is defined" to "If NODE_ENV is not defined".

"Settings" p. 154

In the second bullet, "transparent jsonp" should not be in a monospace font.

"Template Engines" p. 154

Change "many other templates" to "many other template engines".

"Routes" p. 157

Change "the variable name" to "the property name".

"Organization Strategies p. 162

Remove the space between the method name and left paren. in the second code line.

Chapter 10

"Ajax" p. 165

Change "TCP traffic" to "HTTP traffic".

"Setting It Up" p. 167

From Yihang Ho ...
Change the version of websocket.io from "0.1.6" to "0.2.1". The code that follows does not work with version 0.1.6, but does with 0.2.1.

"Setting Up the Server" p. 169 and 170

In the ping function, remove the "+" before "new Date".

"Setting Up the Server" p. 169

In the ping function, fix the indentation of the closing curly brace.

"Setting Up the Client" p. 174

From Yihang Ho ...
In the last codeblock
var ws = new WebSocket('ws://localhost')
should be
var ws = new WebSocket('ws://localhost:3000')

"Close Doesn't Mean Disconnect" p. 177 1st paragraph

Change "appropriately close" to "appropriately closed".

Chapter 11

"Namespaces" p. 181

In calls to "io.of", show passing a callback function.

"Ensuring Reception" p. 190

Remove slashes around the file names "chat.js" and "server.js".

"Extending the Chat" p. 192

Fix indentation of second line of code.

"Integrating with the GrooveShark API" p. 194

In the last code block that is from the file chat.css the one "#results ul" element could be hidden and shown instead of each "#results a" element.

"Integrating with the GrooveShark API" p. 195

There is no need to set form.style.display to 'block' since that is the default.

"Integrating with the GrooveShark API" p. 196

In first paragraph, add quotes around the id attribute value "playing" of the div.

Chapter 12

"Accessing MongoDB: A User Authentication Example" p. 209

Very minor ... change "Is equivalent" to "is equivalent" since it is not the beginning of a new sentence.

"Creating Documents" p. 215

The line before the call to "db.users.find()" is a note to someone named Brian that should have been removed from the final draft.

"Finding Documents" p. 216

Just a comment ... MongoDB needs a better API for creating indexes on multiple properties that avoids the function call nesting in the first code example.

"Defining a Model" p. 220

Change "var PostSchema" to "var postSchema" because it is an object, not a class.

"Setting Up Indexes" p. 223

After the sentence that starts with "To set up more complicated indexes", add an explanation of the values (-1 and 1) in the object passed to BlogPost.index.

"Skipping" p. 225

In callback to Post.count, check err.o

Chapter 13

"Initializing the Script" p. 236

Remove indentation of last line.

"Initializing the Script" p. 237

Remove indentation in the line "db.query('CREATE TABLE item (' +".

"Initializing the Script" p. 237

Mention the "describe" command for showing the columns in a given table.

"Creating Data" p. 240

Does the line ".review" create a div with the class "review"?

"Fetching Data" p. 243

In server.js, remove spaces before the left paren in the function definitions for getItem and getReviews.

"Setting Up the Express App" p. 248

The text "button(type="submit") Add" at the top of the page belongs with the code at the bottom of the previous page.

"Defining Models and Synchronizing" p. 250

Remove the indentation before "Project.hasMany(Task);".

"Defining Models and Synchronizing" p. 250

In the paragraph that starts with "The implication", change "field" to "property".

"Creating Data" p. 252

In the code for server.js, change "..error(next)" to ".error(next)". bottom of the previous page.

"Creating Data" p. 253

In the paragraph that starts with "Notice that", change "field" to "property".

"Retrieving Data" p. 254

In "server.js" after the call to project.getTasks(), change "on('success', function" to "success(function".

"Retrieving Data" p. 254

Is "primary key lookup" always performed on a column named "id"? Does Sequelize add an "id" column to every table it creates?

"Removing Data" p. 254

In the sentence that starts with "Delegation allows", change "anchor that" to "anchor inside a ul that"

"Wrapping Up" p. 256

In the sentence that starts with "For example", chnage "your tasks" to "your tasks titles".

Chapter 14

p. 260

In the last sentence of the paragraph that starts with "What this means", change "durable,, but" to "durable, but".

"Lists" p. 265

At the end of the paragraph that starts with "The LRANGE command", change "of the list" to "up to the end of the list".

"Sorted Sets" p. 266

Change "they are sortable" to "they are sorted".

"Implementing a Social Graph With Node-REDIS" p. 268

In the definition of the User constructor function, remove the space before the left paren.

"Implementing a Social Graph With Node-REDIS" p. 269

In the paragraph that starts with "And when", change "JavaScriopt object" to "JavaScript function".

"Implementing a Social Graph With Node-REDIS" p. 271

In the definition of the User constructor function, remove the space before the left paren.

"Implementing a Social Graph With Node-REDIS" p. 273

In the definition of the create function, remove the space before the left paren.

"Implementing a Social Graph With Node-REDIS" p. 274

In the definition of the hydrate function, remove the space before the left paren.

"Summary" p. 276

In the last paragraph, change "Node.JS" to "Node.js".

Chapter 15

p. 279

In the first paragraph, change "Node.JS" to "Node.js".

"Writing Compatible JavaScript" p. 280

In the first paragraph, change "Node.JS" to "Node.js".

"Writing Compatible JavaScript" p. 281

In the paragraph that starts with "Unlike in", change "Node.JS" to "Node.js".

"Shimming ECMA APIs" p. 282

In the paragraph that starts with "Sometimes the v8", change "v8" to "V8". This paragraph also says that Safari does not support Function#bind. That was probably true when the book was written, but Safari supports it now.

"Cross-Browser Inheritance" p. 285

In all the function definitions at the top of the page (4 of them), remove the space before the left paren.

"A Basic Example" p. 286

Indent the line of code that starts with "log(".

"A Basic Example" p. 286

In log.js, why is "return" used?

"A Basic Example" p. 286

At the end of them browserbuild command, change "out.js" to "compiled.js".

Chapter 16

"Expect" p. 292

In the first sentence, change "you leverage" to "you leveraged".

"Mocha" p. 294

In test.js, why is the second call to describe nested in the first?