Chapter 5
Accessing Databases

Data must persist, and databases are a great way to make that happen. As we’ve seen, Node.js does network I/O asynchronously, and this certainly includes interacting with databases. No matter which database you choose, you’ll have to become comfortable making asynchronous requests to it.

Working with databases will offer a convenient context for exploring the following aspects of Node development.

Architecture and Core

Node.js is fast—really fast. It’s easy in Node to exhaust system resources or overload other systems it talks to. You’ll learn what to do to mitigate these kinds of problems and how to react to them when they happen.

Patterns

Asynchronous JavaScript programming can become complex when you have many tasks that depend on each other. You’ll learn a couple of techniques for executing tasks in batches or in sequence using an npm module called async. You’ll also work extensively with RESTful APIs.

JavaScriptisms

Sometimes JavaScript code gets executed in a different context than where it was originally written. You’ll learn how to export JavaScript functions from one environment to another.

Supporting Code

In previous chapters we’ve tested our code by running it in different scenarios. Here you’ll use common testing tools with npm to code and run unit tests.

Different databases use different protocols for communicating with clients. Some databases use simple text-based commands over TCP, and some have their own binary protocols. Still other databases use Representational State Transfer (REST).

We’ll use CouchDB for exploring databases with Node.[18] CouchDB uses REST for everything, from creating databases to reporting the system status to executing mapreduce queries. Using CouchDB to learn about asynchronous database access in Node has several advantages.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.227.161.225