Over the past few years, Node.js has found its way into the technology stack of Fortune 500 companies, mobile-first start-ups, successful Internet-based businesses, and other enterprises. In addition to validating its power as a platform, this success has exposed a shortage of tools for managing, deploying, and monitoring Node.js applications. Even though the Node.js community is open and collaborative, comprehensive information on how professional Node developers design, test, and push their code into production environments is hard to find.
This book is an attempt to close that gap in knowledge by explaining and documenting techniques and tools that working Node.js developers can use to create scalable, smart, robust, and maintainable software for the enterprise.
After a brief introduction to Node and the philosophy behind its design, you will learn how to install and update your applications on local servers and across the cloud. This foundation is then built upon by proceeding step by step through load balancing and other scaling techniques, explaining how to handle sudden changes in traffic volume and shape, implement version control, and design memory-efficient, stateful, distributed applications.
Once you've completed the groundwork essential to creating production-ready systems, you will need to test and deploy them. Filled with real-world code examples, this book is structured as a progressive workbook explaining strategies for success to be used during each stage of the testing, deploying, monitoring, and maintaining marathon that every successful piece of software runs.
When you've finished this book, you will have learned a set of reusable patterns directly applicable to solving the problems that you are dealing with today and will have laid the foundation to make confident decisions about how to build and deploy your next project.
Chapter 1, Appreciating Node, goes into the thinking behind Node.js, helping you to think clearly about what Node.js is good at, what it is less good at, and how to leverage Node.js to solve real-world challenges.
Chapter 2, Installing and Virtualizing Node Servers, teaches you how to create a basic Node.js application and get it running on a server. You will also learn how to do the same thing on certain popular cloud-hosting providers, such as DigitalOcean and Heroku, additionally learning how to use Docker to create lightweight, easily replicable, virtual machines.
Chapter 3, Scaling Node, explores both vertical and horizontal scaling techniques. You will learn how to use the cluster module to maximize Node's effectiveness on a single server and how to coordinate many distributed Node.js servers to handle increasing network traffic, learning about Nginx load balancing, setting up proxies using message queues, and coordinating interprocess communication in the process.
Chapter 5, Monitoring Applications, explains strategies to effectively monitor your application once it has been deployed. Examples of using various third-party monitoring tools are included as well as examples outlining how you can build your own custom system sampling and logging modules. Finally, we look at debugging techniques, examining several tools and strategies to help you find and prevent runtime bottlenecks.
Chapter 6, Building and Testing, introduces certain considerations when creating a build pipeline for your application. Full examples of using Gulp, Browserify, and npm to create build tools are provided as well as information on testing with Mocha, mocking with Sinon, and using PhantomJS for headless browser testing.
Chapter 7, Deploying and Maintaining, walks you through the entire deployment pipleline, from setting up virtualized development environments to building continuous integration into your workflow. You will learn about using GitHub webhooks and Vagrant and using Jenkins to automate your deployment process. Additionally, the npm package manager will be fully dissected, and strategies for dependency management will be discussed.
You will need to install Node v. 0.12.5 or higher, preferably on a Unix-based operating system, such as Linux or Mac OS X. You will also need to install several tools primarily to set up development and deployment examples:
Use Node Version Manager (nvm) to install Node.js (and npm): https://github.com/creationix/nvm
In addition, these npm packages must be installed globally (npm install <packagename> -g):
Further installation and configuration instructions for these and other packages will be provided, when necessary, as you work through the book.
In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.
Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "Therefore, once we have the page loaded, we send keystrokes (
sendKeys) into the
#source input box with the Italian word
A block of code is set as follows:
variable = produceAValue() print variable // some value is output when #produceAValue is finished.
Any command-line input or output is written as follows:
> This happens first > Then the contents are available, [file contents shown]
New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "You should see You just deployed some Node! displayed."
Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.
To send us general feedback, simply e-mail
<[email protected]>, and mention the book's title in the subject of your message.
If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.
Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.
You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.
Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.
To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.
Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.
Please contact us at
<[email protected]> with a link to the suspected pirated material.
We appreciate your help in protecting our authors and our ability to bring you valuable content.
If you have a problem with any aspect of this book, you can contact us at
<[email protected]>, and we will do our best to address the problem.