You are previewing Node.js Recipes: A Problem-Solution Approach.
O'Reilly logo
Node.js Recipes: A Problem-Solution Approach

Book Description

Node.js Recipes is your one-stop reference for learning how to solve Node.js problems. Node.js is the de facto framework for building JavaScript-powered servers. You will first be introduced to this exciting technology and what it can do, then learn through comprehensive and easy-to-follow recipes that use a problem-solution approach. Node.js Recipes teaches you to fully utilize the Node.js API, and leverage existing modules to build truly exciting projects.

Because Node.js is written in JavaScript on the server, it is accessible to those who not only relish in server-side programming but also web developers who understand the ubiquitous language of the web. Node.js Recipes covers all the essential ingredients required to become a seasoned Node.js developer in no time - become a Node.js pro today!

What you'll learn

  • Learn Node.js's beginnings and what problems it addresses

  • Build an understanding of Node.js's native capabilities

  • Create servers that communicate via TCP/IP, HTTP, and HTTPS

  • Understand and implement test-driven development practices

  • Successfully work with FileSystem, events, and child processes

  • Create a WebSocket server, use Socket.io, and frameworks such as ExpressJS and Yahoo! Mojito

  • Connect to a DataStore using Mongoose, MongoDB, MySQL and CouchDB

  • Implement security and cryptography using HMAC and TLS

  • Test synchronous and asynchronous code, and build a full test suite

  • Debug and deploy your application to Heroku, Nodejitsu and Windows Azure

  • Use Amazon Web Services to successfully host your Node.js application

Who this book is for

Node.js Recipes is for the reader who has some familiarity with JavaScript. They may have experience writing server-side JavaScript, but would like to get a more sound understanding of the capabilities that Node.js holds. This book will give them recipes enabling them to hone their JavaScript skills in a way that will harness Node.js and help them wrangle JavaScript on the server.

Table of Contents

  1. Title Page
  2. Dedication
  3. Contents at a Glance
  4. Contents
  5. About the Author
  6. About the Technical Reviewers
  7. Acknowledgments
  8. CHAPTER 1: Understanding Node.js
    1. 1-1. Installing Node.js on Your Machine
    2. 1-2. Installing the npm Package Manager
    3. 1-3. Understanding CommonJS Modules
    4. 1-4. Writing Modules for Your Application
    5. 1-5. Requiring Modules in Your Application
    6. 1-6. Using npm Modules
    7. 1-7. Getting Started with npm and Dependency
    8. 1-8. Installing a Node.js Version Manager
    9. 1-9. Using Multiple Versions of Node.js on Your Machine
    10. Summary
  9. CHAPTER 2: Networking with Node.js
    1. 2-1. Setting Up a Server
    2. 2-2. Creating Connections to Your Server
    3. 2-3. Configuring Server Defaults
    4. 2-4. Creating a Client
    5. 2-5. Using Sockets to Communicate Between Servers
    6. 2-6. Retrieving Details About Connected Servers
  10. CHAPTER 3: Using the File System
    1. 3-1. Retrieving Directory Structures
    2. 3-2. Navigating Through Directories
    3. 3-3. Manipulating the Directory Structure
    4. 3-4. Watching a Directory for Modifications
    5. 3-5. Reading Files
    6. 3-6. Writing Files
    7. 3-7. Moving Files
    8. 3-8. Symbolically Linking Files
    9. 3-9. Altering File Permissions
    10. 3-10. Watching Files for Modifications
  11. CHAPTER 4: Building a Web Server
    1. 4-1. Setting Up an HTTP Server
    2. 4-2. Using SSL to Build an HTTPS Server
    3. 4-3. Processing Requests on Your Server
    4. 4-4. Sending Responses from Your Server
    5. 4-5. Handling Headers and Status Codes
    6. 4-6. Creating an HTTP Client
    7. 4-7. Processing Client Responses
    8. 4-8. Processing Client Requests
    9. 4-9. Responding to Events
    10. 4-10. Serving a Static Page via the File System
  12. CHAPTER 5: Using Events and Child Processes
    1. 5-1. Creating a Custom Event
    2. 5-2. Adding a Listener for Custom Events
    3. 5-3. Implementing a One-time Event
    4. 5-4. Reducing Callbacks Using Events
    5. 5-5. Spawning a Child with .spawn
    6. 5-6. Running Shell Commands with .exec
    7. 5-7. Executing Shell Files with .execFile
    8. 5-8. Using .fork for Interprocess Communication
    9. Summary
  13. CHAPTER 6: Implementing Security and Cryptography
    1. 6-1. Analyzing Types of Hash Algorithms
    2. 6-2. Hashing Data with createHash
    3. 6-3. Verifying File Integrity with Hashes
    4. 6-4. Using an HMAC to Verify and Authenticate Messages
    5. 6-5. Reviewing OpenSSL Ciphers and Security
    6. 6-6. Using OpenSSL Ciphers to Encrypt Data
    7. 6-7. Using Node.js’s TLS Module for Securing Your Server
    8. 6-8. Encrypting User Credentials with the Crypto Module
    9. 6-9. Using a Third-Party Authentication Module
    10. Summary
  14. CHAPTER 7: Discovering Other Node.js Modules
    1. 7-1. Creating a Simple DNS Server with DNS
    2. 7-2. Handling Streams with the Buffer
    3. 7-3. Clustering with Node.js
    4. 7-4. Working with Query Strings
    5. 7-5. Processing Events with ‘Process’
    6. 7-6. Using Timers
    7. 7-7. Using the V8 Debugger
    8. 7-8. Parsing URLs
    9. 7-9. Using the Console 
  15. CHAPTER 8: Creating a WebSocket Server
    1. 8-1. Implementing a WebSocket Server with WebSocket-Node
    2. 8-2. Listening for WebSocket Events on the Client
    3. 8-3. Building a WebSocket API
    4. 8-4. Using Socket.IO for WebSocket Communications
    5. 8-5. Handling WebSocket Events in a Browser
    6. 8-6. Communicating Server Events via WebSockets
    7. 8-7. Two-way Communications with WebSockets
    8. 8-8. Building a Multiuser Whiteboard with WebSockets
  16. CHAPTER 9: Using Web Server Frameworks
    1. 9-1. Getting Started with Express
    2. 9-2. Using Express to Generate an Application
    3. 9-3. Rendering HTML with Jade
    4. 9-4. Routing with Express
    5. 9-5. Handling Failed Requests in Your Application
    6. 9-6. Designing a RESTful API with ExpressJS
    7. 9-7. Up and Running with Geddy
    8. 9-8. Using Yahoo! Mojito
    9. 9-9. Building a Flatiron Application
  17. CHAPTER 10: Connecting to a Data Store
    1. 10-1. Connecting to MySQL
    2. 10-2. Connecting to Microsoft SQL Server
    3. 10-3. Using PostgreSQL with Node.js
    4. 10-4. Using Mongoose to Connect to MongoDB
    5. 10-5. Modeling Data for Mongoose
    6. 10-6. Connecting to CouchDB
    7. 10-7. Using Redis
    8. 10-8. Connecting to Cassandra
    9. 10-9. Using Riak with Node.js
  18. CHAPTER 11: Testing in Node.js
    1. 11-1. Choosing a Framework for Test-Driven Development or Behavior-Driven Development
    2. 11-2. Creating Tests with the Node.js assert Module
    3. 11-3. Creating Tests with Nodeunit
    4. 11-4. Creating Tests with Mocha
    5. 11-5. Creating Tests with Chai.js
    6. 11-6. Creating Tests with Vows
    7. 11-7. Creating Tests with Should.js
    8. 11-8. Reporting Code Coverage with Node-cover
    9. 11-9. Reporting Code Coverage with istanbul
    10. 11-10. Building a Full Test Suite
    11. 11-11. Implementing Testing into Your Workflow
    12. 11-12. Automating Your Testing
  19. CHAPTER 12: Debugging and Deploying Your Application
    1. 12-1. Logging Information to the Console
    2. 12-2. Using a Graphical Debugging Tool
    3. 12-3. Debugging Your Application in a Production Environment
    4. 12-4. Continuously Running Your Server with Forever
    5. 12-5. Deploying Your Application on Your Own Server
    6. 12-6. Publishing Your Code to npm
    7. 12-7. Using Amazon Web Services to Host Your Application
    8. 12-8. Deploying Your Application Using Heroku
    9. 12-9. Deploying Your Application to Nodejitsu
    10. 12-10. Deploying to Windows Azure
  20. Index