The definitive guide to one of the most important tools of the modern web.
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 book based on the best-selling first edition. It starts at square one and guides you through all the features, techniques, and concepts you'll need to build production-quality Node applications.
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.2.1. Node and V8
1.2.2. Working with feature groups
1.2.3. Understanding Node’s release schedule
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.5.4. Applications suited to Node
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.8.1. An example event emitter
2.8.2. Responding to an event that should occur only once
2.8.3. Creating event emitters: a publish/subscribe example
2.8.4. Extending the event emitter: a file watcher example
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. What is a Node web application?
3.1. A Node web application’s structure
3.1.1. Starting a new project
3.1.2. Comparison with other platforms
3.1.3. What’s next?
3.2. Building a RESTful web service
3.3. Adding a database
3.3.1. Your own model API
3.3.2. Making articles readable and saving them for later
3.4. Adding a user interface
3.4.1. Supporting multiple formats
3.4.2. Rendering templates
3.4.3. Using npm for client-side dependencies
3.5. Summary
Part 2: Building web applications
4. Front-end build systems
4.1. An overview of front-end development with Node
4.2. Using npm to run scripts
4.2.1. Custom npm scripts
4.3. Gulp
4.3.1. Adding Gulp to a project
4.3.2. Creating and running gulp tasks
4.3.3. Watching for changes
4.3.4. Using separate files for larger projects
4.4. Webpack
4.4.1. Bundles and plugins
4.4.2. Configuring and running Webpack
4.4.3. Webpack development server
4.4.4. Loading CommonJS modules and assets
4.4.5. Finding loaders and plugins
4.5. Summary
5. Serverside web frameworks
5.1. Personas
5.1.1. Phil: agency developer
5.1.2. Nadine: open source developer
5.1.3. Alice: product developer
5.2. What is a framework?
5.3. Koa
5.3.1. Setting up
5.3.2. Defining routes
5.3.3. REST APIs
5.3.4. Strengths
5.3.5. Weaknesses
5.4. Kraken
5.4.1. Setting up
5.4.2. Defining routes
5.4.3. REST APIs
5.4.4. Strengths
5.4.5. Weaknesses
5.5. Hapi
5.5.1. Setting up
5.5.2. Defining routes
5.5.3. Plugins
5.5.4. REST APIs
5.5.5. Strengths
5.5.6. Weaknesses
5.6. Sails.js
5.6.1. Setting up
5.6.2. Defining routes
5.6.3. REST APIs
5.6.4. Strengths
5.6.5. Weaknesses
5.7. DerbyJS
5.7.1. Setting up
5.7.2. Defining routes
5.7.3. REST APIs
5.7.4. Strengths
5.7.5. Weaknesses
5.8. Flatiron.js
5.8.1. Setting up
5.8.2. Defining routes
5.8.3. REST APIs
5.8.4. Strengths
5.8.5. Weaknesses
5.9. LoopBack
5.9.1. Setting up
5.9.2. Defining routes
5.9.3. REST APIs
5.9.4. Strengths
5.9.5. Weaknesses
5.10. Comparison
5.10.1. HTTP servers and routes
5.11. Writing modular code
5.12. Persona choices
5.13. Summary
6. Connect and Express in depth
6.1. Connect
6.1.1. Setting up a Connect application
6.1.2. How Connect middleware works
6.1.3. Combining middleware
6.1.4. Middleware ordering
6.1.5. Creating configurable middleware
6.1.6. Using errorhandling middleware
6.2. Express
6.2.1. Generating the application skeleton
6.2.2. Configuring Express and your application
6.2.3. Rendering views
6.2.4. Express routing 101
6.2.5. Authenticating users
6.2.6. Registering new users
6.2.7. Logging in registered users
6.2.8. Userloading middleware
6.2.9. Creating a public REST API
6.2.10. Enabling content negotiation
6.3. Summary
7. Web application templating
7.1. Using templating to keep code clean
7.1.1. Templating in action
7.2. Templating with Embedded JavaScript
7.2.1. Creating a template
7.2.2. Integrating EJS into your application
7.2.3. Using EJS for clientside applications
7.3. Using the Mustache templating language with Hogan
7.3.1. Creating a template
7.3.2. Mustache tags
7.3.3. Fine-tuning Hogan
7.4. Templating with Jade
7.4.1. Jade basics
7.4.2. Logic in Jade templates
7.4.3. Organizing Jade templates
7.5. Summary
8. Storing application data
8.1. Relational databases
8.2. PostgreSQL
8.2.1. Installation and setup
8.2.2. Creating the database
8.2.3. Connecting to Postgres from Node
8.2.4. Defining tables
8.2.5. Inserting data
8.2.6. Updating data
8.2.7. Querying data
8.3. Knex
8.3.1. jQuery for databases
8.3.2. Connecting and running queries with Knex
8.3.3. Swapping the database backend
8.3.4. Beware of leaky abstractions
8.4. MySQL vs PostgreSQL
8.5. ACID Guarantees
8.5.1. Atomicity: transactions either succeed or fail in entirety
8.5.2. Consistency: constraints are always enforced
8.5.3. Isolation: concurrent transactions don’t interfere
8.5.4. Durability: transactions are permanent
8.6. NoSQL
8.7. Distributed Databases
8.8. MongoDB
8.8.1. Installation and Setup
8.8.2. Connecting to MongoDB
8.8.3. Inserting documents
8.8.4. Querying
8.8.5. MongoDB identifiers
8.8.6. Replica sets
8.8.7. Write concerns
8.9. Key-value stores
8.10. Redis
8.10.1. Installation and setup
8.10.2. Initialization
8.10.3. Key-value pairs
8.10.4. Keys
8.10.5. Encoding and data types
8.10.6. Hashes
8.10.7. Lists
8.10.8. Sets
8.10.9. Pub-Sub with channels
8.10.10. Redis performance
8.11. Embedded databases
8.12. LevelDB
8.12.1. LevelUP and LevelDOWN
8.12.2. Installation
8.12.3. API overview
8.12.4. Initialization
8.12.5. Key/value encodings
8.12.6. Reading and writing key-value pairs
8.12.7. Pluggable backends
8.12.8. The modular database
8.13. Serialization and deserialization are expensive
8.14. In-browser storage
8.14.1. Web storage: localStorage and sessionStorage
8.14.2. Reading and writing values
8.14.3. localforage
8.14.4. Reading and writing
8.15. Hosted storage
8.15.1. Simple Storage Service (S3)
8.16. Which database?
8.17. Summary
9. Testing Node applications
9.1. Unit testing
9.1.1. The assert module
9.1.2. Mocha
9.1.3. Vows
9.1.4. Chai
9.1.5. Should.js
9.1.6. Spies and stubs with Sinon.JS
9.2. Functional testing
9.2.1. Selenium
9.3. Dealing with failing tests
9.3.1. Getting more detailed logs
9.3.2. Better stacktraces
9.4. Summary
10. Deploying Node applications and maintaining uptime
10.1. Hosting Node applications
10.1.1. Platform as a Service
10.1.2. Servers
10.1.3. Containers
10.2. Deployment basics
10.2.1. Deploying from a Git repository
10.2.2. Keeping Node running
10.3. Maximizing uptime and performance
10.3.1. Maintaining uptime with Upstart
10.3.2. The cluster API: taking advantage of multiple cores
10.3.3. Hosting static files and proxying
10.4. Summary
Part 3: Beyond web development
11. Writing command-line applications
11.1. Conventions and philosophy
11.2. Introducing parse-json
11.3. Command-line arguments
11.3.1. Parsing command-line arguments
11.3.2. Validating arguments
11.3.3. Passing stdin as a file
11.4. Sharing command-line tools with npm
11.5. Connecting scripts with pipes
11.5.1. Piping data into parse-json
11.5.2. Errors and exit codes
11.5.3. Using pipes in Node
11.5.4. Pipes and command execution order
11.6. Interpreting real-world scripts
11.7. Summary
12. Conquering the desktop with Electron
12.1. Introducing Electron
12.1.1. Electron's stack
12.1.2. Interface design
12.2. Creating an Electron app
12.2.1. The remote module
12.3. Building a full desktop application
12.3.1. Bootstrapping React and Babel
12.3.2. Installing the dependencies
12.3.3. Setting up webpack
12.4. The React app
12.4.1. Defining the Request component
12.4.2. Defining the Response component
12.4.3. Communicating between React components
12.5. Builds and distribution
12.5.1. Packaging
12.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: Automating the web with scraping
B.1. Understanding web scraping
B.1.1. Uses of web scraping
B.1.2. Required tools
B.2. Performing basic web scraping with cheerio
B.3. Handling dynamic content with jsdom
B.4. Making sense of raw data
B.5. Summary
Appendix C: Connect's officially supported middleware
C.1. Middleware for parsing cookies, request bodies, and query strings
C.1.1. cookie-parser: Parse HTTP cookies
C.1.2. Parsing query strings
C.1.3. body-parser: Parse request bodies
C.1.4. compression: Compress outgoing responses
C.2. Middleware that implements core web application functions
C.2.1. morgan: Log requests
C.2.2. serve-favicon: Address bar and bookmark icons
C.2.3. method-override: Fake HTTP methods
C.2.4. vhost: Virtual hosting
C.2.5. express-session: session management
C.3. Middleware that handles web application security
C.3.1. basic-auth: HTTP Basic authentication
C.3.2. csurf: Cross-site request forgery protection
C.3.3. errorhandler: Display errors during development
C.4. Middleware for serving static files
C.4.1. serve-static: Automatically serve files to the browser
C.4.2. serve-index: Generate directory listings
About the Technology
You already know JavaScript. The trick to mastering Node.js is learning how to build applications that fully exploit its powerful asynchronous event handling and non-blocking I/O features. The Node server radically simplifies event-driven real-time apps like chat, games, and live data analytics, and with its incredibly rich ecosystem of modules, tools, and libraries, it's hard to beat!
About the book
Based on the bestselling first edition, Node.js in Action, Second Edition is a completely new book. Packed with practical examples, it teaches you how to create high-performance web servers using JavaScript and Node. You'll master key design concepts such as asynchronous programming, state management, and event-driven programming. And you'll learn to put together MVC servers using Express and Connect, design web APIs, and set up the perfect production environment to build, lint, and test.