Building Scalable Apps with Redis and Node.js

Book description

Develop customized, scalable web apps through the integration of powerful Node.js frameworks

In Detail

Node.js is a JavaScript runtime-based, scalable platform used to develop web applications and network programs on the server side. It allows web designers to access the backend of their projects while also allowing developers, who are willing to learn JavaScript, a chance to design. There are many frameworks that have popped up in recent years, but what makes Node.js unique is that it opens up a whole new frontier for web development and takes a hybrid approach.

This book will help you get to grips with Node.js and implement the knowledge to build efficient web applications. You start with developing a backend web application followed by a frontend interface, and later on deploy it to the cloud platform. This book takes a holistic approach to server-side programming using Node.js in conjunction with different frameworks and tools.

What You Will Learn

  • Build and implement your custom middleware for Express
  • Integrate Socket.IO with Express and use the same authentication
  • Create a secure local store for passwords
  • Use message queues to break down your application into manageable pieces
  • Leverage the power of Redis to create a shared state across many different servers
  • Implement Backbone, Socket.IO, and React together for a fast, dynamic, and real-time frontend
  • Automate your build process with the use of the Grunt.js task runner
  • Build deployment scripts to get servers running your application in the cloud

Table of contents

  1. Building Scalable Apps with Redis and Node.js
    1. Table of Contents
    2. Building Scalable Apps with Redis and Node.js
    3. Credits
    4. About the Author
    5. About the Reviewers
    6. www.PacktPub.com
      1. Support files, eBooks, discount offers, and more
        1. Why subscribe?
        2. Free access for Packt account holders
    7. 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. Downloading the color images of this book
        3. Errata
        4. Piracy
        5. Questions
    8. 1. Backend Development with Express
      1. Node.js and Node Package Manager
      2. Using Express in Node
      3. Using middleware in Express
        1. Creating our own middleware
      4. Adding templates to the mix
        1. Layouts
      5. Using sessions in Express
        1. Using cookies in Express
        2. Adding sessions
        3. Redis as a session store
      6. Processing forms
        1. Cross-Site Request Forgery (CSRF)
      7. Very simple authentication
      8. Setting up a config file for our app
        1. Route mapping
        2. Updating our app to use the config
      9. Methods to extend an application
      10. Summary
    9. 2. Extending Our Development with Socket.IO
      1. Node package versions
      2. Building a simple Socket.IO app
        1. Installing the package
        2. Building the client
        3. Using Python to serve our site
        4. Ping-Pong
        5. Creating some interaction
        6. Adding the browser side
        7. Acknowledgments
      3. Broadcasting a message
      4. Using the disconnect event
      5. Creating namespaces
        1. Building our namespace client
      6. Adding rooms
      7. Using namespaces or rooms
        1. Namespaces
          1. Finding namespaces
        2. When to use rooms
        3. Finding rooms
      8. Using namespaces and rooms together
      9. Using Socket.IO and Express together
        1. Adding Socket.IO to the config
        2. Who are you?
          1. Authorization in Socket.IO
            1. Using the authorization handler
            2. Cookies and sessions
              1. Getting the session
      10. Adding application-specific events
      11. Using Redis as the store for Socket.IO
      12. Socket.IO inner workings
        1. WebSockets
      13. Ideas to take away from this chapter
      14. Summary
    10. 3. Authenticating Users
      1. Node package versions
      2. Let's build our authentication
      3. Registering a Facebook application
      4. Using Passport to authenticate to Facebook
      5. Using Google for authentication
      6. Adding Google authentication to our application
      7. Adding more OAuth providers
      8. Adding secure local authentication
        1. Adding registration
        2. Adding a database
      9. Password-storing theory
      10. OAuth process
      11. Summary
    11. 4. RabbitMQ for Message Queuing
      1. Node package versions
      2. Getting RabbitMQ
        1. Installing on Mac OS X
          1. The RabbitMQ management plugin
        2. Installing on Linux
        3. Installing on Windows
      3. Our first message queue
        1. Using the management interface
        2. Sending messages
        3. Queuing messages
        4. Adding another worker
      4. Sending messages back
        1. Creating StartServer
        2. Building the worker
        3. Charging cards in real time
      5. Adding message queues to PacktChat
        1. Topic exchange
        2. Building the worker
      6. Message queuing in RabbitMQ
      7. Summary
    12. 5. Adopting Redis for Application Data
      1. Node package versions
      2. Installing Redis
        1. Installing on Mac OS X
        2. Installing on Linux
        3. Installing on Windows
      3. Using Redis data structures
        1. Building a simple Redis application
      4. Redis schema
        1. Using a hash
        2. Keys in Redis
      5. Redis persistence
        1. Removing Redis keys
      6. Using Redis as a message queue
      7. Adding Redis to PacktChat
        1. Defining the Redis structures
        2. Creating our Redis functions
      8. Redis is for application state
      9. Summary
    13. 6. Using Bower to Manage Our Frontend Dependencies
      1. Node package versions
      2. Installing and using Bower
      3. Introducing React
      4. Introducing Backbone
        1. Using Backbone models
        2. Using Backbone collections
      5. Summary
    14. 7. Using Backbone and React for DOM Events
      1. Bower package versions
      2. Finishing Socket.IO
      3. Creating React components
        1. React summary
      4. Backbone models
        1. Syncing the models with Socket.IO
        2. Creating the model
        3. Creating collections
      5. The Backbone router
      6. Putting it all together
      7. Updating CSS and the layout
      8. Adding a new worker
      9. Trying out our application
      10. Summary
    15. 8. JavaScript Best Practices for Application Development
      1. Node package versions
      2. Setting up tests
        1. Using Istanbul for code coverage
      3. Setting up different environments
        1. Twelve Factor App
        2. Fixing the config file
        3. Creating our environment files
        4. Adding more environments
      4. Introducing Grunt
        1. Building a basic Grunt file
        2. Automating our tests
        3. Preprocessing our files
        4. Using Grunt to clean out a folder
        5. JSHinting our source files
        6. Concatenating our code
        7. Minifying our code
        8. Grunt summary
      5. Static files and CDNs
        1. Creating an S3 bucket
        2. Python and installing virtual environments
      6. Scripting our new tools
      7. Summary
    16. 9. Deployment and Scalability
      1. Creating servers on EC2
        1. AWS EC2 summary
      2. What is Ansible?
        1. Installing Ansible
        2. Using Ansible roles
          1. Installing RabbitMQ
          2. Installing our application
            1. Deploying the code
          3. Installing the workers
          4. Load balancing multiple application servers
          5. Automating roles
        3. A summary of Ansible
        4. Creating new environments
      3. Scalability
        1. Different types of scalability
          1. Horizontal
          2. Vertical
      4. Summary
    17. 10. Debugging and Troubleshooting
      1. Node packages
      2. Using Chrome Developer Tools
        1. Elements
        2. Network
        3. Sources
        4. Timeline
        5. Profiles
        6. Resources
        7. Audits
        8. Console
      3. Inspecting requests
      4. Debugging
        1. Frontend debugging
        2. Backend debugging
        3. Debugging summary
      5. CPU profiling our application
      6. Taking heap snapshots
        1. Frontend memory leaks
        2. Memory leak summary
      7. Summary
    18. Index

Product information

  • Title: Building Scalable Apps with Redis and Node.js
  • Author(s): Joshua Johanan
  • Release date: September 2014
  • Publisher(s): Packt Publishing
  • ISBN: 9781783984480