You are previewing Node Web Development - Second Edition.
O'Reilly logo
Node Web Development - Second Edition

Book Description

JavaScript is no longer just for browsers and this exciting introduction to Node.js will show you how to build data-intensive applications that run in real time. Benefit from an easy, step-by-step approach that really works.

  • Learn about server-side JavaScript with Node.js and Node modules.

  • Website development both with and without the Connect/Express web application framework.

  • Developing both HTTP server and client applications.

  • In Detail

    Node.js is a JavaScript platform using an event-driven, non-blocking I/O model allowing users to build fast and scalable data-intensive applications that run in real time.

    This book gives you an excellent starting point and goes straight to the heart of developing web applications with Node.js. You will go from a rudimentary knowledge of JavaScript or server-side application development to being able to create and maintain your own Node.js application.

    Node Web Development shows that JavaScript is not just for browsers anymore. It can be used for web application development, for developing any Internet protocol, for real-time applications, and much more. With this book you will learn through practical examples how to use the HTTP Server and client objects as well as both SQL and MongoDB databases. The book explains how application algorithms are expected to cooperate correctly with the event loop, and gives advice on algorithm refactoring for asynchronous execution through the event loop.

    Table of Contents

    1. Node Web Development - Second Edition
      1. Table of Contents
      2. Node Web Development - Second Edition
      3. Credits
      4. About the Author
      5. Acknowledgement
      6. About the Reviewers
      7. www.PacktPub.com
        1. Support files, eBooks, discount offers and more
          1. Why Subscribe?
          2. Free Access for Packt account holders
      8. Preface
        1. What this book covers
        2. What you need for this book
        3. Who this book is for
        4. Conventions
        5. Reader feedback
        6. Customer support
          1. Downloading the example code
          2. Errata
          3. Piracy
          4. Questions
      9. 1. About Node
        1. The capabilities of Node
          1. Server-side JavaScript
        2. Why should you use Node?
          1. Threaded versus asynchronous event-driven architecture
          2. Performance and utilization
            1. Is Node a cancerous scalability disaster?
          3. Server utilization, the bottom line, and green web hosting
        3. What's in a name – Node, Node.js, or Node.JS?
        4. Summary
      10. 2. Setting up Node
        1. System requirements
        2. Installing Node using package managers
          1. Installing on Mac OS X with MacPorts
          2. Installing on Mac OS X with Homebrew
          3. Installing on Linux from package management systems
          4. Installing the Node distribution from nodejs.org
          5. Installing Node on Windows using Chocolatey Gallery
        3. Installing the StrongLoop Node distribution
        4. Installing from source on POSIX-like systems
          1. Installing prerequisites
        5. Installing developer tools on Mac OS X
          1. Installing from source for all POSIX-like systems
          2. Maintaining multiple Node installs simultaneously
        6. Run a few commands; testing the commands
          1. Node's command-line tools
          2. Running a simple script with Node
          3. Launching a server with Node
        7. npm – the Node package manager
        8. Starting Node servers at system startup
        9. Summary
      11. 3. Node Modules
        1. Defining a module
          1. Node modules
          2. Node's algorithm for resolving require(module)
            1. Module identifiers and path names
            2. Local modules within your application
            3. Bundling external dependencies with your application
            4. System-wide modules in NODE_PATH and elsewhere
            5. Complex modules – modules as directories
        2. Node package manager
          1. The npm package format
          2. Finding npm packages
          3. Using the npm commands
            1. Getting help with npm
            2. Viewing package information
            3. Installing an npm package
            4. Installing native code modules on Windows
            5. Installing packages local to a module
            6. Eliminating duplicate modules installed beneath node_modules
            7. Listing the currently installed packages
            8. Package scripts
            9. Editing and exploring installed package content
            10. Updating outdated packages you've installed
            11. Uninstalling an installed npm package
            12. Developing and publishing npm packages
            13. npm configuration settings
          4. Package version strings and ranges
          5. CommonJS modules
            1. Demonstrating module encapsulation
        3. Summary
      12. 4. HTTP Servers and Clients – A Web Application's First Steps
        1. Sending and receiving events with EventEmitters
          1. EventEmitter theory
        2. HTTP server applications
        3. HTTP Sniffer – listening to the HTTP conversation
        4. Web application frameworks
        5. Getting started with Express
          1. Walking through the default Express application
        6. Calculating the Fibonacci sequence with Express
          1. Computationally intensive code and the event loop
            1. Algorithmic refactoring
        7. Making HTTP Client requests
        8. Calling a REST backend service from an Express application
          1. Implementing a simple REST server with Express
          2. Refactoring the Fibonacci application for REST
          3. Some RESTful Node modules
        9. Summary
      13. 5. Implementing a Simple Express Application
        1. Express and the MVC paradigm
        2. Creating the Notes application code
          1. The Notes model
          2. The Notes home page
          3. Adding a new note (create)
          4. Viewing notes (read)
          5. Editing an existing note (update)
          6. Deleting notes (destroy)
        3. Changing the look of an Express application
        4. Scaling up and running multiple instances
        5. Summary
      14. 6. Data Storage and Retrieval
        1. Asynchronizing the Notes application
          1. Injecting the model configuration into routers
          2. The notes router
        2. Storing notes in files
          1. Configuring app.js
        3. Storing notes with the LevelUP data store
          1. Installing LevelUP
          2. LevelUP model code for Notes
          3. Configuring app.js for LevelUP
        4. Storing notes in SQL – SQLite3
          1. Setting up a schema with SQLite3
          2. Model code
          3. Configuring app.js
        5. Storing notes the ORM way with the Sequelize module
          1. Schema setup and model code
          2. Configuring app.js
        6. Storing notes in MongoDB with Mongoose
          1. Implementing the Notes model in Mongoose
          2. Configuring app.js
        7. Summary
      15. 7. Multiuser Authorization, Deployment, Scaling, and Hosting
        1. User authentication
          1. Changes in app.js
          2. The Sequelize-based users model
          3. Routing module for the login, logout, and account pages
          4. Initializing the user table
          5. Running the Notes application
        2. Deploying Notes on Debian
        3. Scaling to use all cores on multi-core servers
        4. Deploying Notes on cloud hosting (AppFog)
        5. Summary
      16. 8. Dynamic Interaction between the Client and Server Application
        1. Adding real-time web features to Notes
        2. Introducing Socket.IO
        3. Initializing Socket.IO with Express
          1. Setting up the client code
        4. Events between the Notes server and client code
          1. Modifying the Notes model to send events
          2. Sending the events from the Notes server
          3. Browser-side event handlers
        5. Running the Notes application with Socket.IO
          1. Listening to the heartbeat and cleaning up when it stops
        6. Sending messages between users
          1. Socket.IO events for sending messages between users
          2. Data model to store messages
          3. Setting up client-side code for sending messages
          4. Dispatching messages between the client- and server-side
          5. Displaying messages to the user
          6. Running Notes and sending messages
        7. Summary
      17. 9. Unit Testing
        1. Testing asynchronous code
        2. Assert – the simplest testing methodology
        3. Testing a model
          1. Executing the tests
        4. Testing router functions
          1. Diagnosing a failing test case
        5. Making it easy to run the tests
        6. Summary
      18. Index