Node.js in Action, Second Edition
Mike Cantelon, Alex Young, Marc Harter, T.J. Holowaychuk, and Nathan Rajlich
  • MEAP began April 2015
  • Publication in June 2017 (estimated)
  • ISBN 9781617292576
  • 450 pages (estimated)
  • printed in black & white

GET MORE WITH MANNING

An eBook copy of the previous edition, Node.js in Action (First Edition), is included at no additional cost. It will be automatically added to your Manning Bookshelf within 24 hours of purchase.


Node.js in Action, Second Edition is a thoroughly-revised new edition that starts at square one and guides you through all the features, techniques, and concepts you'll need to build production-quality Node applications. To begin, you'll ease into Node development with a simple screen scraping application. Next, you'll walk through some working examples where you'll learn the basics of a few common types of Node applications. As you read, you'll dive into the many different uses of Node: traditional web applications, real-time web applications, non-web network applications, and even desktop applications. Whether you're just getting started with Node or you're looking to expand your skills, you'll appreciate the clear coverage of key concepts such as asynchronous programming, data storage, and output templating, and interact with the filesystem to create non-HTTP applications like TCP/IP servers and command-line tools. This book covers the ongoing development of Node via io.js and the emerging ECMAScript 6 features.

Table of Contents detailed table of contents

Part 1: Introduction

1. Welcome to Node.js

1.1. A typical Node web application

1.1.1. Non-blocking I/O

1.1.2. The event loop

1.2. ECMAScript 6, Node, and V8

1.3. Installing Node

1.4. Node's built-in tools

1.4.1. npm

1.4.2. The core modules

1.4.3. The debugger

1.5. The three main types of Node program

1.5.1. Web applications

1.5.2. Command-line tools and daemons

1.5.3. Desktop applications

1.6. Summary

2. Node programming fundamentals

2.1. Organizing and reusing Node functionality

2.2. Starting a new Node project

2.2.1. Creating modules

2.3. Fine-tuning module creation using module.exports

2.4. Reusing modules using the node_modules folder

2.5. Caveats

2.6. Asynchronous programming techniques

2.7. Handling one-off events with callbacks

2.8. Handling repeating events with event emitters

2.9. Challenges with asynchronous development

2.10. Sequencing asynchronous logic

2.11. When to use serial flow control

2.12. Implementing serial flow control

2.13. Implementing parallel flow control

2.14. Leveraging community tools

2.15. Summary

3. Automating the web with scraping

3.1. What is web scraping?

3.1.1. Uses of web scraping

3.1.2. Required tools

3.2. Basic web scraping with cheerio

3.3. Handling dynamic content with JSDOM

3.4. Making sense of raw data

3.4.1. Extracting unstructured values

3.5. Summary

Part 2: Building web applications

4. What is a Node web application?

4.1. A Node web application’s structure

4.1.1. Starting a new project

4.1.2. Comparison with other platforms

4.1.3. What’s next?

4.2. Building a RESTful web service

4.3. Adding a database

4.3.1. Your own model API

4.3.2. Making articles readable and saving them for later

4.4. Adding a user interface

4.4.1. Supporting multiple formats

4.4.2. Rendering templates

4.4.3. Using npm for client-side dependencies

4.5. Summary

5. Front-end build systems

5.1. An overview of front-end development with Node

5.2. Using npm to run scripts

5.2.1. Custom npm scripts

5.3. Gulp

5.3.1. Adding Gulp to a project

5.3.2. Creating and running gulp tasks

5.3.3. Watching for changes

5.3.4. Using separate files for larger projects

5.4. Webpack

5.4.1. Bundles and plugins

5.4.2. Configuring and running Webpack

5.4.3. Webpack development server

5.4.4. Loading CommonJS modules and assets

5.4.5. Finding loaders and plugins

5.5. Summary

6. Server—side web frameworks

6.1. Personas

6.2. What is a framework?

6.3. Koa

6.3.1. Setting up

6.3.2. Defining routes

6.3.3. REST APIs

6.3.4. Strengths

6.3.5. Weaknesses

6.4. Kraken

6.4.1. Setting up

6.4.2. Defining routes

6.4.3. REST APIs

6.4.4. Strengths

6.4.5. Weaknesses

6.5. Hapi

6.5.1. Setting up

6.5.2. Defining routes

6.5.3. Plugins

6.5.4. REST APIs

6.5.5. Strengths

6.5.6. Weaknesses

6.6. Sails.js

6.6.1. Setting up

6.6.2. Defining routes

6.6.3. REST APIs

6.6.4. Strengths

6.6.5. Weaknesses

6.7. DerbyJS

6.7.1. Setting up

6.7.2. Defining routes

6.7.3. REST APIs

6.7.4. Strengths

6.7.5. Weaknesses

6.8. Flatiron.js

6.8.1. Setting up

6.8.2. Defining routes

6.8.3. REST APIs

6.8.4. Strengths

6.8.5. Weaknesses

6.9. LoopBack

6.9.1. Setting up

6.9.2. Defining routes

6.9.3. REST APIs

6.9.4. Strengths

6.9.5. Weaknesses

6.10. Comparison

6.10.1. HTTP servers and routes

6.11. Writing modular code

6.12. Persona choices

6.13. Summary

7. Connect and Express in depth

7.1. Connect

7.1.1. Setting up a Connect application

7.1.2. How Connect middleware works

7.1.3. Combining middleware

7.1.4. Middleware ordering

7.1.5. Creating configurable middleware

7.1.6. Using error—handling middleware

7.2. Express

7.2.1. Generating the application skeleton

7.2.2. Configuring Express and your application

7.2.3. Rendering views

7.2.4. Express routing 101

7.2.5. Authenticating users

7.2.6. Registering new users

7.2.7. Logging in registered users

7.2.8. User—loading middleware

7.2.9. Creating a public REST API

7.2.10. Enabling content negotiation

7.3. Summary

8. Web application templating

8.1. Using templating to keep code clean

8.1.1. Templating in action

8.2. Templating with Embedded JavaScript

8.2.1. Creating a template

8.2.2. Integrating EJS into your application

8.2.3. Using EJS for client—side applications

8.3. Using the Mustache templating language with Hogan

8.3.1. Creating a template

8.3.2. Mustache tags

8.3.3. Fine-tuning Hogan

8.4. Templating with Jade

8.4.1. Jade basics

8.4.2. Logic in Jade templates

8.4.3. Organizing Jade templates

8.5. Summary

9. Storing application data

9.1. Relational databases

9.2. PostgreSQL

9.2.1. Installation and setup

9.2.2. Creating the database

9.2.3. Connecting to Postgres from Node

9.2.4. Defining tables

9.2.5. Inserting data

9.2.6. Updating data

9.2.7. Querying data

9.3. Knex

9.3.1. Connecting and running queries with Knex

9.3.2. Swapping the database backend

9.4. MySQL vs PostgreSQL

9.5. ACID Guarantees

9.6. NoSQL

9.7. Distributed Databases

9.8. MongoDB

9.8.1. Installation and Setup

9.8.2. Connecting to MongoDB

9.8.3. Inserting documents

9.8.4. Querying

9.8.5. MongoDB identifiers

9.8.6. Replica sets

9.8.7. Write concerns

9.9. Key-value stores

9.10. Redis

9.10.1. Installation and setup

9.10.2. Initialization

9.10.3. Key-value

9.10.4. Keys

9.10.5. Encoding and data types

9.10.6. Hashes

9.10.7. Lists

9.10.8. Sets

9.10.9. Pub-Sub with channels

9.11. Embedded databases

9.12. LevelDB

9.12.1. LevelUP and LevelDOWN

9.12.2. Installation

9.12.3. API overview

9.12.4. Initialization

9.12.5. Key/value encodings

9.12.6. Reading and writing key-value pairs

9.12.7. Pluggable backends

9.12.8. The modular database

9.13. Serialization and deserialization are expensive

9.14. In-browser storage

9.14.1. Web storage: localStorage and sessionStorage

9.14.2. Reading and writing values

9.14.3. localforage

9.14.4. Reading and writing

9.15. Hosted storage

9.15.1. Simple Storage Service (S3)

9.16. Which database?

9.17. Summary

Part 3: Testing and deployment

10. Testing Node applications

10.1. Unit testing

10.1.1. The assert module

10.1.2. Mocha

10.1.3. Vows

10.1.4. Chai

10.1.5. Should.js

10.1.6. Spies and stubs with Sinon.JS

10.2. Functional testing

10.2.1. Selenium

10.3. Dealing with failing tests

10.3.1. Getting more detailed logs

10.3.2. Better stacktraces

10.4. Summary

11. Deploying Node applications and maintaining uptime

11.1. Hosting Node applications

11.1.1. Platform as a Service

11.1.2. Servers

11.1.3. Containers

11.2. Deployment basics

11.2.1. Deploying from a Git repository

11.2.2. Keeping Node running

11.3. Maximizing uptime and performance

11.3.1. Maintaining uptime with Upstart

11.3.2. The cluster API: taking advantage of multiple cores

11.3.3. Hosting static files and proxying

11.4. Summary

Part 4: Beyond web development

12. Writing command-line applications

12.1. Conventions and philosophy

12.2. Introducing parse-json

12.3. Command-line arguments

12.3.1. Parsing command-line arguments

12.3.2. Validating arguments

12.3.3. Passing stdin as a file

12.4. Sharing command-line tools with npm

12.5. Connecting scripts with pipes

12.5.1. Piping data into parse-json

12.5.2. Errors and exit codes

12.5.3. Using pipes in Node

12.5.4. Pipes and command execution order

12.6. Interpreting real-world scripts

12.7. Summary

13. Conquering the desktop with Electron

13.1. Introducing Electron

13.1.1. Electron's stack

13.1.2. Interface design

13.2. Creating an Electron app

13.2.1. The remote module

13.3. Building a full desktop application

13.3.1. Bootstrapping React and Babel

13.4. The React app

13.4.1. Defining the Request component

13.4.2. Defining the Response component

13.4.3. Communicating between React components

13.5. Builds and distribution

13.5.1. Packaging

13.6. Summary

Appendixes

Appendix A: Installing Node

A.1. Installing Node using an installer

A.1.1. The macOS installer

A.1.2. The Windows installer

A.2. Other ways to install Node

A.2.1. Installing Node from source

A.2.2. Installing Node with a package manager

Appendix B: Connect's officially supported middleware

B.1. Middleware for parsing cookies, request bodies, and query strings

B.1.2. Parsing query strings

B.1.3. body-parser: Parse request bodies

B.1.4. compression: Compress outgoing responses

B.2. Middleware that implements core web application functions

B.2.1. morgan: Log requests

B.2.2. serve-favicon: Address bar and bookmark icons

B.2.3. method-override: Fake HTTP methods

B.2.4. vhost: Virtual hosting

B.2.5. express-session: session management

B.3. Middleware that handles web application security

B.3.1. basic-auth: HTTP Basic authentication

B.3.2. csurf: Cross-site request forgery protection

B.3.3. errorhandler: Display errors during development

B.4. Middleware for serving static files

B.4.1. serve-static: Automatically serve files to the browser

B.4.2. serve-index: Generate directory listings

About the Technology

JavaScript on the server? You bet. Node.js is a JavaScript framework that can be used to create scalable, high-performance web applications. Using asynchronous I/O, the server can do more than one thing at a time, a key requirement for real-time apps like chat, games, and live statistics. And since it's JavaScript, you use the same language end to end. There's a lot to learn, though, so let's get started!

What's inside

  • How asynchronous programming and the event loop work
  • Which community-created extensions to use to avoid re-inventing the wheel
  • Application examples including chat, microblogging, and more

About the reader

Perfect for a web developer transitioning from Rails, Django, or PHP. Requires basic knowledge of JavaScript. No prior experience with Node.js needed.

About the authors

As skilled practitioners, expert teachers and trainers, and contributors to the core framework, authors Mike Cantelon, Alex Young, Marc Harter, T.J. Holowaychuk, and Nathan Rajlich represent the best of the Node.js development community.


Manning Early Access Program (MEAP) Read chapters as they are written, get the finished eBook as soon as it’s ready, and receive the pBook long before it's in bookstores.
Buy
MEAP combo $49.99 pBook + eBook
MEAP eBook $39.99 pdf + ePub + kindle

FREE domestic shipping on three or more pBooks