Table of Contents
Preface
Chapter 1: What is Node?
Chapter 2: Setting up Node
Chapter 3: Node Modules
Chapter 4: Variations on a Simple Application
Chapter 5: A Simple Web Server, EventEmitters, and HTTP Clients
Chapter 6: Data Storage and Retrieval
Index
- Chapter 1: What is Node?
- What can you do with Node?
- Server-side JavaScript
- Why should you use Node?
- Architecture: Threads versus asynchronous event-driven
- Performance and utilization
- Server utilization, the bottom line, and green web hosting
- Spelling: Node, Node.js, or Node.JS?
- Summary
- Chapter 2: Setting up Node
- System requirements
- Installation on POSIX-like systems (Linux, Solaris, Mac, and so on)
- Installing prerequisites
- Installing developer tools on Mac OS X
- Installing in your home directory
- What's the rationale for a home directory installation?
- Installing in a system-wide directory
- Installing on Mac OS X with MacPorts
- Installing on Mac OS X with homebrew
- Installing on Linux from package management systems
- Maintaining multiple Node installs simultaneously
- Run a few commands; test your installation
- Node's command-line tools
- Running a simple script with Node
- Launching a server with Node
- Installing npm—the Node package manager
- Starting Node servers at system startup
- Using all CPU cores on multi-core systems
- Summary
- Chapter 3: Node Modules
- What's a module?
- Node modules
- How does Node resolve require('module')?
- Module identifiers and path names
- Local modules within your application
- Bundling external dependencies with your application
- System-wide modules in the require.paths directories
- Complex modules—modules as directories
- Node package Manager (npm)
- npm package format
- Finding npm packages
- Using the npm commands
- Getting help with npm
- Viewing package information
- Installing an npm package
- Using installed packages
- What packages are currently installed?
- Package scripts
- Editing and exploring installed package content
- Updating outdated packages you've installed
- Uninstalling an installed npm package
- Developing and publishing npm packages
- npm configuration settings
- Package version strings and ranges
- CommonJS modules
- Demonstrating module encapsulation
- Summary
- Chapter 4: Variations on a Simple Application
- Creating a Math Wizard
- To use a web framework, or not
- Implementing the Math Wizard with Node (no frameworks)
- Routing requests in Node
- Handling URL query parameters
- Multiplying numbers
- Calculating the other mathematical functions
- Extending the Math Wizard
- Long running calculations (fibonacci numbers)
- What "complete web server" features are missing?
- Using Connect to implement the Math Wizard
- Installing Connect and other setup
- Connecting with Connect
- Using Express to implement the Math Wizard
- Implementing the Express Math Wizard
- Handling errors
- Parameterized URLs and data services
- Parametrized URLs in Express
- The mathematics server (and client)
- Refactoring Math Wizard to use math server
- Summary
- Chapter 5: A Simple Web Server, EventEmitters, and HTTP Clients
- Sending and receiving events with EventEmitters
- EventEmitter theory
- HTTP Sniffer—listening to the HTTP conversation
- Implementing a basic web server
- The Basic Server implementation
- Basic Server core (basicserver.js)
- The Favicon handler (faviconHandler.js)
- The static file handler (staticHandler.js)
- A configuration for Basic Server (server.js)
- Virtual host configuration with Basic Server
- A shorturl module for Basic Server
- MIME types and the MIME npm package
- Cookie handling
- Virtual hosts and request routing
- Making HTTP Client requests
- Summary
- Chapter 6: Data Storage and Retrieval
- Data storage engines for Node
- SQLite3—Lightweight in-process SQL engine
- Installation
- Implementing the Notes application with SQLite3
- Database abstraction module—notesdb-sqlite3.js
- Initializing the database—setup.js
- Display notes on the console—show.js
- Putting together the Notes web application—app.js
- Notes application templates
- Running the SQLite3 Notes application
- Handling and debugging errors
- Using other SQL databases with Node
- Mongoose—Node interface to MongoDB
- Installing Mongoose
- Implementing the Notes application with Mongoose
- Database abstraction module—notesdb-mongoose.js
- Initializing the database—setup.js
- Display notes on the console—show.js
- Putting it together in an application—app.js
- Other MongoDB database support
- A quick look at authenticating your users
- Summary


