Smashing Node.js: JavaScript Everywhere [NOOK Book]


From the World’s Number One Resource for Web Designers and Developers – The Ultimate Guide to the Technology That’s Taking the Web Development World by Storm

Node.js is a powerful web development framework written in JavaScript that makes it simpler and easier than ever to develop robust, highly-scalable server-side web apps. Smashing Node.js shows you what Node.js is and how to put it to work on your next project. Packed with real-world examples that demonstrate why Node.js is ...

See more details below
Smashing Node.js: JavaScript Everywhere

Available on NOOK devices and apps  
  • NOOK Devices
  • Samsung Galaxy Tab 4 NOOK 7.0
  • Samsung Galaxy Tab 4 NOOK 10.1
  • NOOK HD Tablet
  • NOOK HD+ Tablet
  • NOOK eReaders
  • NOOK Color
  • NOOK Tablet
  • Tablet/Phone
  • NOOK for Windows 8 Tablet
  • NOOK for iOS
  • NOOK for Android
  • NOOK Kids for iPad
  • PC/Mac
  • NOOK for Windows 8
  • NOOK for PC
  • NOOK for Mac
  • NOOK for Web

Want a NOOK? Explore Now

NOOK Book (eBook)
$25.99 price
(Save 42%)$44.99 List Price
Note: This NOOK Book can be purchased in bulk. Please email us for more information.


From the World’s Number One Resource for Web Designers and Developers – The Ultimate Guide to the Technology That’s Taking the Web Development World by Storm

Node.js is a powerful web development framework written in JavaScript that makes it simpler and easier than ever to develop robust, highly-scalable server-side web apps. Smashing Node.js shows you what Node.js is and how to put it to work on your next project. Packed with real-world examples that demonstrate why Node.js is quickly becoming the tool of choice among web developers everywhere, it gets you quickly up and running with the knowledge and skills you need to:

  • Make sense of Node’s Event-Loop Architecture, Non-Blocking I/O, and Event-Driven Programming
  • Master the Ins and Outs of Node’s Apis
  • Effortlessly Implement Real-Time Technologies, Such as Shocket.IO and HTML5 Websockets
  • Program Apps That Scale Up to Support Vast Numbers of Simultaneous Connections Across Multiple Servers
  • Leverage Node’s Ability to Support an Array of Database and Data Storage Tools
  • Write Code That Can Handle Tens of Thousands of Connections at a Time—On One Machine
  • Interact in Real-Time With Other Developers on a Companion Web Site Featuring Additional Chapters and More Annotated Examples—Source Code Included

Beautifully illustrated with tons of full-color illustrations and packed with useable source code, Smashing Node.js is your total guide to the revolutionary web development tool.

Read More Show Less

Product Details

  • ISBN-13: 9781119963103
  • Publisher: Wiley
  • Publication date: 8/14/2012
  • Series: Smashing Magazine Book Series
  • Sold by: Barnes & Noble
  • Format: eBook
  • Edition number: 2
  • Pages: 320
  • Sales rank: 698,590
  • File size: 4 MB

Meet the Author

Guillermo Rauch is CTO and co-founder of San Francisco-based education startup LearnBoost. He is the inventor of several renowned Node.js projects, and he has been a speaker at JSConf as well as Nod.js workshops.

Read More Show Less

Table of Contents


Chapter 1: The Setup 7

Installing on Windows 8

Installing on OS X 8

Installing on Linux 8

Compiling 9

Ensuring that it works 9

The Node REPL 9

Executing a file 10

NPM 10

Installing modules 11

Defining your own module 12

Installing binary utilities 13

Exploring the NPM registry 14

Summary 14

Chapter 2: JavaScript: An Overview 15

Introduction 15

Basic JavaScript 16

Types 16

Type hiccups 16

Functions 18

this, Function#call, and Function#apply 18

Functionarity 19

Closures 19

Classes 20

Inheritance 20

try {} catch {} 21

v8 JavaScript 22

Object#keys 22

Array#isArray 23

Array methods 23

String methods 24


Function#bind 24

Function#name 24

_proto_ (inheritance) 25

Accessors 25

Summary 26

Chapter 3: Blocking and Non-blocking IO 27

With great power comes great responsibility 28

Blocking-ness 29

A single-threaded world 31

Error handling 33

Stack traces 35

Summary 37

Chapter 4: Node JavaScript 39

The global object 40

Useful globals 40

The module system 41

Absolute and relative modules 41

Exposing APIs 44

Events 45

Buffers 47

Summary 48


Chapter 5: CLI and FS APIs: Your First Application 51

Requirements 52

Writing your first program 52

Creating the module 53

Sync or async? 54

Understanding streams 55

Input and ouput 57

Refactoring 59

Interacting with the fs 61

Exploring the CLI 63

Argv 63

Working directory 64

Environmental variables 65

Exiting 65

Signals 65

ANSI escape codes 66

Exploring the fs module 66

Streams 67

Watch 67

Summary 68

Chapter 6: TCP 69

What are the characteristics of TCP? 70

Connection-oriented communication and same-order delivery 70

Byte orientation 70

Reliability 71

Flow control 71

Congestion control 71

Telnet 71

A TCP chat program 74

Creating the module 74

Understanding the net.server API 74

Receiving connections 76

The data event 77

State and keeping track of connections 79

Wrap up 81

An IRC Client program 83

Creating the module 83

Understanding the net#Stream API 84

Implementing part of the IRC protocol 84

Testing with a real-world IRC server 85

Summary 85

Chapter 7: HTTP 87

The structure of HTTP 88

Headers 89

Connections 93

A simple web server 94

Creating the module 95

Printing out the form 95

Methods and URLs 97

Data 99

Putting the pieces together 102

Bullet-proofing 103

A Twitter web client 104

Creating the module 104

Making a simple HTTP request 104

Sending a body of data 106

Getting tweets 107

A superagent to the rescue 110

Reloading HTTP servers with up 111

Summary 112


Chapter 8: Connect 115

A simple website with HTTP 116

A simple website with Connect 119

Middleware 121

Writing reusable middleware 122

Static middleware 127

Query 128

Logger 129

Body parser 131

Cookies 134

Session 134

REDIS sessions 140

methodOverride 141

basicAuth 141

Summary 144

Chapter 9: Express 145

A simple express app 146

Creating the module 146

HTML 146

Setup 147

Defining routes 148

Search 150

Run 152

Settings 153

Template engines 154

Error handling 155

Convenience methods 155

Routes 157

Middleware 159

Organization strategies 160

Summary 162

Chapter 10: WebSocket 163

AJAX 164

HTML5 WebSocket 166

An Echo Example 167

Setting it up 167

Setting up the server 168

Setting up the client 169

Running the server 170

Mouse cursors 171

Setting up the example 171

Setting up the server 172

Setting up the client 174

Running the server 176

The Challenges Ahead 177

Close doesn’t mean disconnect 177

JSON 177

Reconnections 177

Broadcasting 177

WebSockets are HTML5: Older browsers don’t support them 177

The solution 178

Summary 178

Chapter 11: Socket.IO 179

Transports 180

Disconnected versus closed 180

Events 180

Namespaces 181

A chat program 182

Setting up the program 182

Setting up the server 182

Setting up the client 183

Events and Broadcasting 185

Ensuring reception 190

A DJ-by-turns application 191

Extending the chat 191

Integrating with the Grooveshark API 193

Playing 196

Summary 201


Chapter 12: MongoDB 205

Installation 207

Accessing MongoDB: A user authentication example 208

Setting up the application 208

Creating the Express app 208

Connecting to MongoDB 212

Creating documents 214

Finding documents 215

Authentication middleware 217

Validation 218

Atomicity 219

Safe mode 219

Introducing Mongoose 220

Defining a model 220

Defining nested keys 222

Defining embedded documents 222

Setting up indexes 222

Middleware 223

Inspecting the state of the model 223

Querying 224

Extending queries 224

Sorting 224

Making Selections 224

Limiting 225

Skipping 225

Populating keys automatically 225

Casting 225

A mongoose example 226

Setting up the application 226

Refactoring 226

Setting up models 227

Summary 229

Chapter 13: MySQL 231

node-mysql 232

Setting it up 232

The Express app 232

Connecting to MySQL 234

Initializing the script 234

Creating data 238

Fetching data 242

sequelize 244

Setting up sequelize 245

Setting up the Express app 245

Connecting sequelize 248

Defining models and synchronizing 249

Creating data 250

Retrieving data 253

Removing data 254

Wrapping up 256

Summary 257

Chapter 14: Redis 259

Installing Redis 261

The Redis query language 261

Data types 262

Strings 263

Hashes 263

Lists 265

Sets 265

Sorted sets 266

Redis and Node 266

Implementing a social graph with node-redis 267

Summary 276


Chapter 15: Code Sharing 279

What can be shared? 280

Writing compatible JavaScript 280

Exposing modules 280

Shimming ECMA APIs 282

Shimming Node APIs 283

Shimming browser APIs 284

Cross-browser inheritance 284

Putting it all together: browserbuild 285

A basic example 286

Summary 288

Chapter 16: Testing 289

Simple testing 290

The test subject 290

The test strategy 290

The test program 291

Expect.JS 292

API overview 292

Mocha 294

Testing asynchronous code 295

BDD style 297

TDD style 298

Exports style 298

Taking Mocha to the browser 299

Summary 300

Read More Show Less

Customer Reviews

Average Rating 5
( 2 )
Rating Distribution

5 Star


4 Star


3 Star


2 Star


1 Star


Your Rating:

Your Name: Create a Pen Name or

Barnes & Review Rules

Our reader reviews allow you to share your comments on titles you liked, or didn't, with others. By submitting an online review, you are representing to Barnes & that all information contained in your review is original and accurate in all respects, and that the submission of such content by you and the posting of such content by Barnes & does not and will not violate the rights of any third party. Please follow the rules below to help ensure that your review can be posted.

Reviews by Our Customers Under the Age of 13

We highly value and respect everyone's opinion concerning the titles we offer. However, we cannot allow persons under the age of 13 to have accounts at or to post customer reviews. Please see our Terms of Use for more details.

What to exclude from your review:

Please do not write about reviews, commentary, or information posted on the product page. If you see any errors in the information on the product page, please send us an email.

Reviews should not contain any of the following:

  • - HTML tags, profanity, obscenities, vulgarities, or comments that defame anyone
  • - Time-sensitive information such as tour dates, signings, lectures, etc.
  • - Single-word reviews. Other people will read your review to discover why you liked or didn't like the title. Be descriptive.
  • - Comments focusing on the author or that may ruin the ending for others
  • - Phone numbers, addresses, URLs
  • - Pricing and availability information or alternative ordering information
  • - Advertisements or commercial solicitation


  • - By submitting a review, you grant to Barnes & and its sublicensees the royalty-free, perpetual, irrevocable right and license to use the review in accordance with the Barnes & Terms of Use.
  • - Barnes & reserves the right not to post any review -- particularly those that do not follow the terms and conditions of these Rules. Barnes & also reserves the right to remove any review at any time without notice.
  • - See Terms of Use for other conditions and disclaimers.
Search for Products You'd Like to Recommend

Recommend other products that relate to your review. Just search for them below and share!

Create a Pen Name

Your Pen Name is your unique identity on It will appear on the reviews you write and other website activities. Your Pen Name cannot be edited, changed or deleted once submitted.

Your Pen Name can be any combination of alphanumeric characters (plus - and _), and must be at least two characters long.

Continue Anonymously
Sort by: Showing all of 2 Customer Reviews
  • Anonymous

    Posted March 30, 2013


    Jello man! <br >

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted October 11, 2012

    Great introduction to node.js

    Guilhermo does a great job showing the principles behind the development for node.js, covering the main modules by writing usable apps. Simply, a book that any webdeveloper should have in it's library.

    Was this review helpful? Yes  No   Report this review
Sort by: Showing all of 2 Customer Reviews

If you find inappropriate content, please report it to Barnes & Noble
Why is this product inappropriate?
Comments (optional)