You are previewing Sams Teach Yourself Node.js in 24 Hours.
O'Reilly logo
Sams Teach Yourself Node.js in 24 Hours

Book Description

In just 24 sessions of one hour or less, Sams Teach Yourself Node.js in 24 Hours will help you master the Node.js platform and use it to build server-side applications with extraordinary speed and scalability. Using this text’s straightforward, step-by-step approach, you’ll move from basic installation, configuration, and programming all the way through real-time messaging between browser and server, testing and deployment. Every lesson and case-study application builds on what you’ve already learned, giving you a rock-solid foundation for real-world success!

Step-by-step instructions carefully walk you through the most common Node.js development tasks.

Quizzes and Exercises at the end of each chapter help you test your knowledge.

By the Way notes present valuable additional information related to the discussion.

Did You Know? tips offer advice or show you easier ways to perform tasks.

Watch Out! cautions alert you to possible problems and give you advice on how to avoid them.

Learn how to…

·         Create end-to-end applications entirely in JavaScript

·         Master essential Node.js concepts like callbacks and quickly create your first program

·         Create basic sites with the HTTP module and Express web framework

·         Manage data persistence with Node.js and MongoDB

·         Debug and test Node.js applications

·         Deploy Node.js applications to thirdparty services, such as Heroku and Nodester

·         Build powerful real-time solutions, from chat servers to Twitter clients

·         Create JSON APIs using JavaScript on the server

·         Use core components of the Node.js API, including processes, child processes, events, buffers, and streams

·         Create and publish a Node.js module

Table of Contents

  1. Title Page
  2. Copyright Page
  3. Contents at a Glance
  4. Table of Contents
  5. About the Author
  6. Dedication
  7. Acknowledgments
  8. We Want to Hear from You!
  9. Reader Services
  10. Introduction
    1. Who Should Read This Book?
    2. Why Should I Learn Node.js?
    3. How This Book Is Organized
    4. Code Examples
    5. Conventions Used in This Book
  11. Part I. Getting Started
    1. Hour 1. Introducing Node.js
      1. What Is Node.js?
      2. What You Can Do with Node.js
      3. Installing and Creating Your First Node.js Program
      4. Summary
      5. Q&A
      6. Workshop
      7. Exercises
    2. Hour 2. npm (Node Package Manager)
      1. What Is npm?
      2. Installing npm
      3. Installing Modules
      4. Using Modules
      5. How to Find Modules
      6. Local and Global Installation
      7. How to Find Module Documentation
      8. Specifying Dependencies with package.json
      9. Summary
      10. Q&A
      11. Workshop
      12. Exercises
    3. Hour 3. What Node.js Is Used For
      1. What Node.js Is Designed to Do
      2. Understanding I/O
      3. Dealing with Input
      4. Networked I/O Is Unpredictable
      5. Humans Are Unpredictable
      6. Dealing with Unpredictability
      7. Summary
      8. Q&A
      9. Workshop
      10. Exercises
    4. Hour 4. Callbacks
      1. What Is a Callback?
      2. The Anatomy of a Callback
      3. How Node.js Uses Callbacks
      4. Synchronous and Asynchronous Code
      5. The Event Loop
      6. Summary
      7. Q&A
      8. Workshop
      9. Exercises
  12. Part II. Basic Websites With Node.js
    1. Hour 5. HTTP
      1. What Is HTTP?
      2. HTTP Servers with Node.js
      3. HTTP Clients with Node.js
      4. Summary
      5. Q&A
      6. Workshop
      7. Exercises
    2. Hour 6. Introducing Express
      1. What Is Express?
      2. Why Use Express?
      3. Installing Express
      4. Creating a Basic Express Site
      5. Exploring Express
      6. Introducing Jade
      7. Summary
      8. Q&A
      9. Workshop
      10. Exercises
    3. Hour 7. More on Express
      1. Routing in Web Applications
      2. How Routing Works in Express
      3. Adding a GET Route
      4. Adding a POST Route
      5. Using Parameters in Routes
      6. Keeping Routes Maintainable
      7. View Rendering
      8. Using Local Variables
      9. Summary
      10. Q&A
      11. Workshop
      12. Exercises
    4. Hour 8. Persisting Data
      1. What Is Persistent Data?
      2. Writing Data to a File
      3. Reading Data from a File
      4. Reading Environment Variables
      5. Using Databases
      6. Using MongoDB with Node.js
      7. Summary
      8. Q&A
      9. Workshop
      10. Exercises
  13. Part III. Debugging, Testing, and Deploying
    1. Hour 9. Debugging Node.js Applications
      1. Debugging
      2. The STDIO Module
      3. The Node.js Debugger
      4. Node Inspector
      5. A Note on Testing
      6. Summary
      7. Q&A
      8. Workshop
      9. Exercises
    2. Hour 10. Testing Node.js Applications
      1. Why Test?
      2. The Assert Module
      3. Third-Party Testing Tools
      4. Behavior Driven Development
      5. Summary
      6. Q&A
      7. Workshop
      8. Exercises
    3. Hour 11. Deploying Node.js Applications
      1. Ready to Deploy!
      2. Hosting in the Cloud
      3. Heroku
      4. Cloud Foundry
      5. Nodester
      6. Other PaaS Providers
      7. Summary
      8. Q&A
      9. Workshop
      10. Exercises
  14. Part IV. Intermediate Sites with Node.js
    1. Hour 12. Introducing Socket.IO
      1. Now for Something Completely Different
      2. Brief History of the Dynamic Web
      3. Socket.IO
      4. Basic Socket.IO Example
      5. Sending Data from the Server to Clients
      6. Broadcasting Data to Clients
      7. Bi-Directional Data
      8. Summary
      9. Q&A
      10. Workshop
      11. Exercises
    2. Hour 13. A Socket.IO Chat Server
      1. Express and Socket.IO
      2. Adding Nicknames
      3. Summary
      4. Q&A
      5. Workshop
      6. Exercises
    3. Hour 14. A Streaming Twitter Client
      1. Streaming APIs
      2. Signing Up for Twitter
      3. Using Twitter’s API with Node.js
      4. Extracting Meaning from the Data
      5. Pushing Data to the Browser
      6. Creating a Real-Time Lovehateometer
      7. Summary
      8. Q&A
      9. Workshop
      10. Exercises
    4. Hour 15. JSON APIs
      1. APIs
      2. JSON
      3. Sending JSON Data with Node.js
      4. Creating JSON from JavaScript Objects
      5. Consuming JSON Data with Node.js
      6. Creating a JSON API with Node.js
      7. Summary
      8. Q&A
      9. Workshop
      10. Exercises
  15. Part V. Exploring the Node.js API
    1. Hour 16. The Process Module
      1. What Processes Are
      2. Exiting and Errors in Processes
      3. Processes and Signals
      4. Sending Signals to Processes
      5. Creating Scripts with Node.js
      6. Passing Arguments to Scripts
      7. Summary
      8. Q&A
      9. Workshop
      10. Exercises
    2. Hour 17. The Child Process Module
      1. What Is a Child Process?
      2. Killing a Child Process
      3. Communicating with a Child Process
      4. The Cluster Module
      5. Summary
      6. Q&A
      7. Workshop
      8. Exercises
    3. Hour 18. The Events Module
      1. Understanding Events
      2. Demonstrating Events Through HTTP
      3. Playing Ping-Pong with Events
      4. Programming Event Listeners Dynamically
      5. Summary
      6. Q&A
      7. Workshop
      8. Exercises
    4. Hour 19. The Buffer Module
      1. A Primer on Binary Data
      2. Binary to Text
      3. Binary and Node.js
      4. What Are Buffers in Node.js?
      5. Writing to Buffers
      6. Appending to Buffers
      7. Copying Buffers
      8. Modifying Strings in Buffers
      9. Summary
      10. Q&A
      11. Workshop
      12. Exercises
    5. Hour 20. The Stream Module
      1. A Primer on Streams
      2. Readable Streams
      3. Writable Streams
      4. Piping Streams
      5. Streaming MP3s
      6. Summary
      7. Q&A
      8. Workshop
      9. Exercises
  16. Part VI. Further Node.js Development
    1. Hour 21. CoffeeScript
      1. What Is CoffeeScript?
      2. Installing and Running CoffeeScript
      3. Why Use a Pre-Compiler?
      4. Features of CoffeeScript
      5. Debugging CoffeeScript
      6. Reactions to CoffeeScript
      7. Summary
      8. Q&A
      9. Workshop
      10. Exercises
    2. Hour 22. Creating Node.js Modules
      1. Why Create Modules?
      2. Popular Node.js Modules
      3. The package.json File
      4. Folder Structure
      5. Developing and Testing Your Module
      6. Adding an Executable
      7. Using Object-Oriented or Prototype-Based Programming
      8. Sharing Code Via GitHub
      9. Using Travis CI
      10. Publishing to npm
      11. Publicizing Your Module
      12. Summary
      13. Q&A
      14. Workshop
      15. Exercises
    3. Hour 23. Creating Middleware with Connect
      1. What Is Middleware?
      2. Middleware in Connect
      3. Access Control with Middleware
      4. Summary
      5. Q&A
      6. Workshop
      7. Exercises
    4. Hour 24. Using Node.js with Backbone.js
      1. What Is Backbone.js?
      2. How Backbone.js Works
      3. A Simple Backbone.js View
      4. Creating Records with Backbone.js
      5. Summary
      6. Q&A
      7. Workshop
      8. Exercises
  17. Index
  18. Add Pages