Errata

Node: Up and Running

Errata for Node: Up and Running

Submit your own errata for this product.

The errata list is a list of errors and their corrections that were found after the product was released.

The following errata were submitted by our customers and have not yet been approved or disproved by the author or editor. They solely represent the opinion of the customer.

Color Key: Serious technical mistake Minor technical mistake Language or formatting error Typo Question Note Update

Version Location Description Submitted by Date submitted
Other Digital Version xvii
2nd paragraph

ebook format only, on ibooks: "italic" is not italic

nicrizzo  Sep 17, 2011 
Other Digital Version ?
EJS Examples

The twitter example using EJS is utterly incomplete and leaves out a ton of key information needed to come anywhere close to getting the example to work. As others have already mentioned, you need to install ejs to begin with, need to create the initial layout.ejs file and name all other files with .ejs extensions and call app.set("view engine", "ejs"). All of this is absolutely vital information and wasn't mentioned in any way at all. The book up to this point has been great. I'm hoping the rest of the book doesn't have similar serious omissions.

Keith Peters  Jun 16, 2012 
Other Digital Version I-2
Entire section

The Express API has changed for 3.x. You should either post the correct code somewhere or else include a package.json with the version of Express that works designated as a dependency. And talk about npm packages, of course.

Anonymous  Feb 17, 2013 
Other Digital Version 2.0
Let's Build Twitter example

Once I got the EJS layout the author lost me on the details.
Does the rendering part go into the main program file?
Where does the index template and partial templates go?
I appreciate having to type n the all code as it helps me learn more then just adding stuff to files but I think a bit more direction on where these things go might be helpful.

Kevin MacPherson  May 15, 2012 
Other Digital Version 2-19
2nd paragraph

No matter what I do, I cannot get the Twitter example to work with ejs.

First I tried it as written, got:

Error: failed to locate view "index"

Then I tried installing ejs and adding app.set('view engine', 'ejs'); per the previous erratum and got the same error.

Then I read through the Express docs, which are equally obtuse, and got nowhere.

It would help if you mentioned to call the layout file "layout.ejs", and where to put the layout.ejs file, and what extension to give the index file, and where to put it, and whether or not ejs needs to be installed. As it stands, this example is very frustrating because it doesn't work as written.

Tom Igoe  Jun 09, 2012 
PDF Page 4
2nd paragraph

A few 'typos':

"To acheive any asperations of sharing code?" -> To achieve any aspirations of sharing code?

"Due to the increasingly complexity of client applications?" -> Due to the increasing complexity of client applications

"having a server-side environment that use JavaScript?" -> having a server-side environment that uses JavaScript

"quickly becoming the dominent platform" -> quickly becoming the dominant platform

Lindsay Davies  May 25, 2011 
PDF Page 7
3rd paragraph

"Each browser has their own JavaScript runtimes: Spider Monkey for Firefox..."

Should be:

"Each browser has their own JavaScript runtimes: J?gerMonkey for Firefox..."

Anonymous  Jun 13, 2011 
PDF, Other Digital Version Page 12
2nd paragraph

proceedural instead of procedural
fundtions instead of functions

nicrizzo  Sep 17, 2011 
PDF, Other Digital Version Page 14
list, 2nd paragraph

deligating instead of delegating

nicrizzo  Sep 17, 2011 
PDF Page 15
2nd Paragraph

Chapter 4

Original sentence is:

"Serial is obvious. Do this I/O, when it is finished do that I/O. Serial is also easy to understand do this I/O and that I/O at the same time."

I think the second sentence should start with the word "Parallel" and should be:

"Parallel is also easy to understand, do this I/O and that I/O at the same time."

Greg Swanson  May 18, 2011 
PDF, Other Digital Version Page 15
1st paragraph

proceeedural instead of procedural

nicrizzo  Sep 17, 2011 
PDF, Other Digital Version Page 16
last paragraph

consiquence instead of consequence

nicrizzo  Sep 17, 2011 
Printed Page 21
top of page

node book-chat.js

where did book-chat.js come from (the examples were previously chat.js).

Marty Leisner  Aug 19, 2012 
Printed Page 22
Example 2-11

clientList[i].writeable is undefined.

I know this is a property of the Stream super class but it seems net.Socket does not know about this property.

When the code is run as listed in the book with say 3 clients, all clients that not satisfying the

clientList[i]!==client

are added to cleanup[], as clientList[i].writeable is undefined. Adding a

console.log(clientList[i].writeable)

Before the check against writeable will show this. Adding the code from Example 2-12 will confirm this, logging the following to console:

[TypeError: Cannot read property 'writeable' of undefined]

I'm using v0.8..15 so that might be the issue?

Joseph Campbell  Dec 15, 2012 
PDF, ePub, Mobi Page 24
Example 2-14

The express module no longer inherits the http module. Stdout/err details are below.

[james@echo js_code]# node ch02-14.js
Warning: express.createServer() is deprecated, express
applications no longer inherit from http.Server,
please use:

var express = require("express");
var app = express()

James Conner  Oct 15, 2012 
PDF Page 25
Example 2-15. Adding a basic API

In Example 2-15 the following line of code:

var app = express.createServer()

Node says that .createServer() has been deprecated. Use this instead:
var app = express()

Shadoobie  Mar 09, 2013 
PDF Page 25
example 2-15

bodyParser is no longer in express 4. It should be insalled independently. See here https://github.com/visionmedia/express/wiki/Migrating-from-3.x-to-4.x

Albert  Apr 16, 2014 
PDF Page 25
app.post('/send', express.bodyParser(), function(req, res) {

When you try this example now you get an error explaining that most middleware is no longer packaged with express. So the examples don't work. Would it be possible to have the author update code examples when necessary on your website?

David Posner  Oct 30, 2016 
PDF, Other Digital Version Page 26
1st paragraph

unerstand instead of understand

nicrizzo  Sep 17, 2011 
Printed Page 27
assert call in sample code

I believe assert.strictEqual(...) should be assert.deepEqual(...)

Curt Carpenter  May 11, 2012 
27
Example 2-16

The assert test for the Twitter server didn't work for me due to newline characters in the data string. I got round this by converting the data string to a JSON object and comparing that with an object. There are fewer quotes this way so it's harder to mistype.

data = JSON.parse(data);
assert.deepEqual(data, {status:"ok", message:"Tweet received"});

This issue was discussed on Stackoverflow:
http://stackoverflow.com/questions/11421974

sillypog  Oct 30, 2012 
PDF Page 27
Example 2-16. A test for the POST API

On page 25
The response to a send is a peice of JSON as such:
{status:"ok", message:"Tweet received"}

Later on page 27 we test for the peice of JSON with an assert.strictEquals call and use this for our comparison:
'{"status":"ok","message":"Tweet received"}'

I think that these two pieces of JSON differ and the test fails as a result. Use the same two pieces of JSON and the assert.strictEquals will succeed.

Shadoobie  Mar 09, 2013 
29
example 2-18, 2-20, 2-21, and 2-22

While the text describes the structure of the Express app, it fails to actually name these files. I found that naming the file "layout", "layout.js", "layout.html" all failed.

I finally succeeded in making this example work by
1- installing ejs by entering "npm install ejs"
2- naming the template files with a ".ejs" extension
3- setting "app.set('view engine', 'ejs')

Was this the intended solution? Did I miss something in the text? Was this the result of version differences? (I just let MacPorts install node v0.6.14)

Anonymous  May 10, 2012 
29
Examples 2-18 through 2-22

The EJS section is completely incomprehensible if you don't already know the technology and know what these files should be named or where they should be placed.

Anonymous  May 19, 2012 
PDF Page 29
example 2-18

In ejs 1.0.0, function partial has been removed. Instead, use code like below:
<% tweets.forEach(function(tweet){ %>
<% include partials/chirp %>
<% }) %>

Inheritance is note working, should use include:
<% include header %>
you original body code
<% include footer %>

Need tell express to use ejs explicitly:
app.set('view engine', 'ejs')
Or
res.render('index.ejs', function(rep, res){...})

Following the code in book, style.css is not accessable. Need add:
app.use('/public', express.static(__dirname + '/public'));
I'm not sure this is the right way, but it works.

Albert  Apr 16, 2014 
PDF Page 30
Example 2-20. An index template to show tweets and let people post new tweets

On Page 30
Example 2-20. An index template to show tweets and let people post new tweets

Use of the partial is no longer supported in EJX 3.x (EJS 3.1.0)
* The book had this: <%- partial('partials/chirp', tweets) %>
* I replaced it with this: <% include partials/chirp%>

This may have had an effect on the contents of partials/chirp.ejs :
Page 33
Example 2-21. A partial template for rendering chirps
* The book had this: <p><%= chirp %></p>
* I replaced that with this: <p><%= tweets %></p>

Shadoobie  Mar 10, 2013 
PDF, Other Digital Version Page 30
Example 2-19

For the Chirpie example, I was unable to get the local variables to work, most likely due to the many different Node.js and Express changes.

Finally I found that you simply just need to remove the 'locals' part. So change the following example from this:

res.render('index', {
locals: {
'title': title,
'header': header,
'tweets': tweets,
stylesheets: ['/public/style.css']
}
})

To this:
res.render('index', {
'title': title,
'header': header,
'tweets': tweets,
stylesheets: ['/public/style.css']
})

I ended up having to also change other things about this example but as far as the local variables, this worked for me. Thank you for the book!

Hines Vaughan III  Jan 26, 2015 
PDF Page 31
Bottom: example 2-23

The for loop does "i+=0" and it should be "i+=1"

Kevin Beam  May 09, 2012 
PDF Page 31
Example 2-23. A small function to check for text/html in an accept header

Page 31
Example 2-23. A small function to check for text/html in an accept header

function acceptsHtml(header) {
var accepts = header.split(',')
for(i=0;i<accepts.length;i+=0) {
if (accepts[i] === 'text/html') { return true }
}

To fix:
* change: for(i=0;i<accepts.length;i+=0) {
* to be: for(i=0;i<accepts.length;i+=1) {

Also for an older Android device:
* change: if (accepts[i] === 'text/html') { return true }
* to be: if (accepts[i] === 'text/html' || accepts[i] === 'text/html;q=0.9') { return true }

Shadoobie  Mar 10, 2013 
32
Example 2-23/ 2-24

The addition of the acceptsHtml function seems to break the test case built earlier in the chapter:

assert.js:104
throw new assert.AssertionError({
^
AssertionError: "TypeError: Cannot call method 'split' of undefined\n at acceptsHtml

Anonymous  May 10, 2012 
PDF Page 41
example 3-3

missing closing parentheses:

fs.readFile('foo.txt', 'utf8', function(err, data) {
console.log(data);
};
fs.readFile('bar.txt', 'utf8', function(err, data) {
console.log(data);
};

should read:

fs.readFile('foo.txt', 'utf8', function(err, data) {
console.log(data);
});

fs.readFile('bar.txt', 'utf8', function(err, data) {
console.log(data);
});

also, in order the snippet to be runnable it should begin with:

fs = require('fs');

lina mist  May 21, 2012 
PDF Page 42
Example 3-5

The book lacks an example of "... , two groups of parallel requests could execute serially: do this and that together, then do other and another together." [p. 41]

How can you execute two parallel I/O events in node and execute another group of I/O events when both finish?

Example 3-5 could be extended to make the db and ws request in parallel and render the page after both finish.

Anonymous  Aug 07, 2012 
Printed Page 42
United States


In "Example 3.5 Naming function calls in callbacks", the nested inline function declarations that are now named are missing the _function_ keyword in their declaration.

Anonymous  Jul 31, 2013 
Printed Page 51

In example 3-14 "killing Zombie workers", the function "createWorker" contains an error probably due to a change of the Cluster API. This is for the author to determine.

Line 5 of the function should read: workers[worker.process.pid] = ...

Mathias Behne  Sep 07, 2012 
PDF Page 56
Example 4-2

The 'utils' module should just be 'util'.

Kevin Beam  May 10, 2012 
PDF Page 57
Last sentence of first paragraph

The sentence refers to the "sys.inherits" method and it should be "util.inherits".

Kevin Beam  May 10, 2012 
PDF Page 83
Second paragraph from bottom

"The block sizes vary between algorithms:
blowfish, for example, uses 40-byte blocks."

Actually, it's 64-bit (8-byte), not 40-byte.

Vladimir Makhnovskiy  Oct 04, 2012 
ePub Page 84
United States

The Let's Build Twitter is severely lacking in information. Moreover with updates to Express and EJS there are some lines of code that just don't work.

I'm not trying to plug my own blog (its not really a blog more a place where I brain dump my own findings/projects) but if you want a solution please see: http://www.samk3nny.com/?p=120.

There may be improvements to this and in time, my fixes may become redundant. But as of 11th January 2014, with much gnashing of teeth, I got the Twitter, aka Chirpie, app to work.

Enjoy.

Sam

Sam Kenny  Jan 11, 2014 
ePub Page 643
ebook version example 2-15

node twitter.js
connect.multipart() will be removed in connect 3.0
visit https://github.com/senchalabs/connect/wiki/Connect-3.0 for alternatives
connect.limit() will be removed in connect 3.0

Anonymous  Oct 23, 2013 
Other Digital Version 999
Chapter 2 after example 2.4

This sentence has a syntax issue:
"When we issues a greeting to the client we can now do it using a unique name for that client."

Juan Lanus  Jan 30, 2013 
ePub Page 1174
middle

the EJS example states "The tweets are also coming out in chronological order...We'll fix that too"

but that never happens, there's no text whatsoever on addressing this.

Anonymous  Nov 12, 2012