Book Image

Node Web Development - Second Edition

By : David Herron
Book Image

Node Web Development - Second Edition

By: David Herron

Overview of this book

Table of Contents (17 chapters)
Node Web Development Second Edition
Credits
About the Author
Acknowledgement
About the Reviewers
www.PacktPub.com
Preface
Index

Scaling up and running multiple instances


Now that we've gotten this far, surely you'll have played around with the application a bit, and will have created, read, updated, and deleted many notes.

Suppose for a moment that this isn't a toy application, but one that is interesting enough to draw a million users a day. Serving a high load typically means adding servers, load balancers, and many other things. A core part is to have multiple instances of the application running at the same time to spread out the load.

Let's see, then, what happens when you run multiple instances of the Notes application at the same time.

The first thing to consider is making sure the instances are on different ports. In the default version of app.js you will find this line:

  app.set('port', process.env.PORT || 3000);

What this does is look in the user's environment variables, and if PORT is set, then the application will run on that port (localhost:PORT). If PORT is not set then it defaults to 3000, explaining why...