I’ve been writing and maintaining so many Node.js scripts lately that I’ve lost count. Node modules allow you to extend scripts to do just about anything you need. There are several Node.js modules that I find myself using over and over again in nearly every project I work on. Here are a few of my favorites that I’m sure will make writing your Node.js scripts easier and more bulletproof. All of these modules are well-documented and supported.
Bluebird is a promise library that outperforms ES6’s and other native promise implementations. Bluebird can get very complex, but I find that
Promise.all(), and your standard thenables handle 95% of my needs.
Moment & Moment Timezone
Most of my scripts run on Amazon Web Services, so using the AWS-SDK helps manage everything from security to interacting with SNS and other AWS services. If you’re using AWS Lambda, then it is already available and you don’t need to include it as a dependency.
Interacting with a MySQL or Aurora database is made much simpler using this excellent module by Doug Wilson. Couple this with the Bluebird promise library using
Promise.promisifyAll(require("mysql/lib/Connection").prototype); and managing asynchronous data calls is extremely easy.
NodeRedis is another great project for managing connections to your Redis server or ElasticCache cluster. Support for batching makes sending multiple requests simple, significantly cutting down roundtrips to the server and speeding up your application.
Validator is a great validation module that will validate strings as email, UUIDs, FQDNs, etc. There are also a bunch of sanitizers that can be used to normalize text.
What are your favorite Node.js modules?
Update: Someone asked me about
async / await instead of promises. I think that is a great approach, but I publish a lot of Node.js on AWS Lambda. As of now it only supports up to v6.10, so I’d have to polyfill.