Monthly Archives: June 2017

How to get, use, and close a DB connection using promises

By | Uncategorized | No Comments

The first two patterns we looked at in this series were Node.js callbacks and the Async module. While effective, those patterns are not the only ways of writing asynchronous code. Patterns built around concepts such as “deferreds” and “promises” were first introduced to the JavaScript community via third party libraries like Q and Bluebird. Over time a native implementation of promises was added to ECMAScript, then implemented in V8, and later integrated into Node.js.
Read More

How to get, use, and close a DB connection using the Async module

By | Uncategorized | 2 Comments

The first pattern we looked at in this series was the Node.js callback pattern. As I mentioned there, that pattern alone will only get you so far. Eventually, you’ll want to construct asynchronous workflows that process elements in a collection serially or run several tasks in parallel. You could write your own library, but why reinvent the wheel when you could just use Async, one of the most popular Node.js libraries ever. In this post, we’ll take a look at Async to see how it can help you write asynchronous code in Node.js.
Read More

How to get, use, and close a DB connection using various async patterns

By | Uncategorized | No Comments

It seems simple enough: get a connection to the database, use it to do some work, then close it when you’re done. But due to the asynchronous nature of Node.js, coding this sequence isn’t as straightforward as it seems. There are lots of options for writing asynchronous code with Node.js, and each one requires the sequence to be coded differently. In this series, I’ll provide some examples that demonstrate how to get, use, and close a connection using various async patterns.
Read More