Deploying Node.js

Book description

Learn how to build, test, deploy, monitor, and maintain your Node.js applications at scale

In Detail

Node.js is a popular choice for teams that need to design, build, test, deploy, maintain, and monitor large-scale distributed systems. Starting with a detailed overview of the Node.js architecture, this book covers topics that will help in application development, testing, deployment, and maintenance.

You will learn about concurrency, event loops, callbacks and streams. Furthermore, step-by-step instructions on deploying applications to providers such as DigitalOcean and Heroku will be provided, including information on setting up load balancers and proxies. Message queues and other techniques for managing state and session data at scale will also be covered.

A series of examples on deploying your Node.js applications in production environments are provided, including a discussion on setting up continuous deployment and integration for your team. Popular tools for testing, deploying, building, and monitoring Node.js applications are covered, helping you get up and running quickly.

What You Will Learn

  • Learn the strengths of Node.js and how to optimize your code to make it ready for deployment into production

  • Use Docker and Vagrant to create many virtual instances of your Node.js applications

  • Deploy Node.js repositories to the cloud using Heroku, OpenShift, and DigitalOcean

  • Utilize native Node.js modules, or Nginx, to load balance your applications

  • Optimize your Node runtime by tweaking V8, managing memory intelligently, and using Redis to manage state data

  • Discover how to use Gulp, Browserify, npm, Mocha, Chai, Sinon, and other tools to simplify your build/test/release process

  • Manage your production deployments with Git, Jenkins, and Ansible

  • Table of contents

    1. Deploying Node.js
      1. Table of Contents
      2. Deploying Node.js
      3. Credits
      4. About the Author
      5. About the Reviewers
        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. Errata
          3. Piracy
          4. Questions
      8. 1. Appreciating Node
        1. Understanding Node's unique design
          1. Concurrency
          2. Parallelism and threads
          3. Concurrency and processes
          4. Events
          5. The event loop
        2. The implications of Node's design on system architects
          1. Building large systems out of small systems
          2. Streams
        3. Using full-stack JavaScript to maximum effect
          1. Hot code
          2. Browserify
        4. Summary
      9. 2. Installing and Virtualizing Node Servers
        1. Getting a basic Node server up and running
          1. Hello world
          2. Making HTTP requests
          3. Proxying and tunneling
          4. HTTPS, TLS (SSL), and securing your server
          5. Creating a self-signed certificate for development
          6. Installing a real SSL certificate
        2. Installing applications on Heroku
          1. Add-ons
          2. Git
          3. Managing configuration variables
          4. Managing your deployment
        3. Installing applications on OpenShift
          1. Installing a Node application and MongoDB
          2. Deploying your app
        4. Using Docker to create lightweight virtual containers
          1. First, some Unix
          2. Getting started with Docker
          3. Creating a Dockerfile
          4. Building and running a Docker image
        5. Summary
      10. 3. Scaling Node
        1. Scaling vertically across multiple cores
          1. spawn(command, [arguments], [options])
          2. fork(modulePath, [arguments], [options])
          3. exec(command, [options], callback)
          4. execFile
          5. Communicating with your child process
            1. child.connected
            2. child.stdin
            3. child.stdout
            4. child.stderr
            6. child.kill([signal])
            7. child.disconnect()
            8. child.send(message, [sendHandle])
          6. The cluster module
            1. cluster.isMaster
            2. cluster.isWorker
            3. cluster.worker
            4. cluster.workers
            5. cluster.setupMaster([settings])
            6. cluster.fork([env])
            7. cluster.disconnect([callback])
            8. cluster events
            10. worker.process
            11. worker.suicide
            12. worker.send(message, [sendHandle])
            13. worker.kill([signal])
            14. worker.disconnect()
        2. Scaling horizontally across different machines
          1. Using Nginx
            1. Deploying an Nginx load balancer on DigitalOcean
            2. Installing and configuring Nginx
          2. Load balancing with Node
            1. Using node-http-proxy
          3. Using message queues
          4. Using Node's UDP Module
        3. Summary
      11. 4. Managing Memory and Space
        1. Dealing with large crowds
          1. Microservices
          2. Redis pub/sub
          3. Microservices with Seneca
        2. Reducing memory usage
          1. Use streams, not buffers
          2. Understanding prototypes
          3. Memory-efficient data structures with Redis
            1. Using bitwise operations to analyze user actions over time
              1. Setting, getting, and counting bits
              2. Bitmasks and filtering results
            2. Using HyperLogLog to count unique anonymous visitors
        3. Taming V8 and optimizing performance
          1. Optimizing JavaScript
            1. Numbers and tracing optimization/de-optimization
            2. Objects and arrays
            3. Functions
        4. Caching strategies
          1. Using Redis as a cache
          2. Deploying CloudFlare as a CDN
        5. Managing sessions
          1. JSON Web Token authentication and sessions
        6. Summary
      12. 5. Monitoring Applications
        1. Dealing with failure
          1. The 'domain' module
          2. Catching process errors
          3. Logging
            1. Logging with UDP
            2. Logging with Morgan
        2. Modifying behavior in changing environments
          1. Node REPL
          2. Remotely monitoring and managing Node processes
        3. Profiling processes
        4. Using third-party monitoring tools
          1. PM2
            1. Monitoring
          2. Nodetime
        5. Using New Relic for monitoring
        6. Summary
      13. 6. Building and Testing
        1. Building with Gulp, Browserify, and Handlebars
          1. Using Gulp
          2. Erecting a build scaffold
          3. Running and testing your build
        2. Using Node's native testing tools
          1. The Node debugger
          2. The 'assert' module
        3. Testing with Mocha, Chai, Sinon, and npm
          1. Mocha
          2. Chai
          3. Sinon
            1. Spies
            2. Stubs
            3. Mocks
        4. Automated browser testing with PhantomJS and CasperJS
          1. Headless testing with PhantomJS
          2. Navigation scenarios with CasperJS
        5. Summary
      14. 7. Deploying and Maintaining
        1. Using GitHub webhooks
          1. Enabling webhooks
          2. Implementing a build/deploy system using webhooks
        2. Synchronizing local and deployed builds
          1. Developing locally with Vagrant
          2. Provisioning with Ansible
        3. Integrating, delivering, and deploying
          1. Continuous integration
          2. Continuous delivery
          3. Continuous deployment
          4. Building and deploying with Jenkins
          5. Deploying to Heroku
        4. Package maintenance
          1. Understanding Semver
          2. Managing packages with npm
            1. Designing a dependency tree
        5. Summary
      15. Index

    Product information

    • Title: Deploying Node.js
    • Author(s): Sandro Pasquali
    • Release date: July 2015
    • Publisher(s): Packt Publishing
    • ISBN: 9781783981403