Chapter 7. The Data Store

In the previous few chapters, we learned how to create basic servers using Node.js and how to communicate between our client and server using AJAX. One of the more interesting applications involved keeping track of the number of mentions of certain words on Twitter and displaying counts on the client.

One of the major problems with this application is that it stores all of its information in the Node.js program’s memory. That means that if we shut down our server process the word counts disappear with it. This is not the behavior that we want because we’ll often need to shut down our server to update it or, more commonly, our server may shut itself down due to a bug. When either of these things happen, we would like all of the counts that we’ve taken so far to remain intact.

To solve this problem, we’ll need to use some sort of data storage application that runs independently of our program. In this chapter, we’ll learn two different approaches to solving this problem using NoSQL data stores. Specifically, we’ll study Redis and MongoDB, and we’ll learn how to integrate them into our Node.js applications.

NoSQL Versus SQL

If you’ve studied databases, you’ve probably seen the acronym SQL (sometimes pronounced sequel), which stands for Structured Query Language. It’s a language that is used to ask questions of a database stored in a relational format. Relational databases store data as cells in tables, where the rows of the tables can easily be cross-referenced ...

Get Learning Web App Development now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.