A quick breakdown of the most useful JavaScript modules that I find myself using over and over again. This is an opinionated article that focuses on general-purpose modules and utilities that Iāve found invaluable to NodeJS and frontend JavaScript development. It wonāt be exhaustive or include any special-purpose modules, as those types of are indeed awesome but tend to be a bit overwhelming. awesome lists Yeahhh we all love npmmmmm huzzahhhhhh!!! (Image Credit: ) npm Command LineĀ Tools Letās get started with some extremely useful command line tools. - A better . np npm publish If youāre an npm author, Iād highly recommend checking out , as it makes the process of bumping versions, adding git release tags, and publishing to npm a breeze, especially once you start having more than a couple of modules to maintain. Itās also worth noting by as a solid alternative. np release Zeit Image Credit: by np SindreĀ Sorhus - A better package manager compatible with . yarn npm Although npm is a lot faster than previous versions, I still find to be preferable to npm for local development for its speed and consistency. Either way, youāre working with the same database of npm modules under the hood, and imho thereās no clear winner between the two. You should pick whichever package manager best suits your projectās needs. v5 yarn As a JS developer in 2018, I would, however, make sure that youāre at least familiar with both and and be comfortable switching off between them. npm yarn - An opinionated code formatter. prettier Prettier enforces a consistent style by parsing your code and re-printing it with its own rules that take the maximum line length into account, wrapping code when necessary. I love and have been a long-time user of JavaScript in particular, but the idea behind automatic code formatters like and is undeniably attractive. eslint Standard Style prettier gofmt As developers, we spend way too much time and mental energy worrying about code presentation and styling, whereas alleviates the need for those thought processes and allows you to focus on what youāre writing instead of how youāre writing it. prettier Image Credit: prettier - Extremely simple deployments. now Now is absolutely the best free deployment system that exists today in terms of simplicity, reliability, and feature set. Itās great for testing static and dynamic deployments and scales up nicely if and when you require more servers. Aaaaaaaaaand did I mention that itās until you want to scale up?! free It plays extremely well with Node.js and JS-powered webapps. Iād also highly recommend checking out the rest of offerings as well, as their team is comprised by some of the best JS devs the community has to offer. Zeitās Image Credit: Zeit - Free tool for recording high quality terminal sessions. asciinema See my previous blog post ā ā for a breakdown of how you can take advantage of to produce quality code demos & screencasts like the pros. Making your Code Beautiful asciinema Promises This section really deserves an entire article unto itself, especially now that have started becoming the de facto standard paradigm for concurrent programming in JavaScript. With that being said, Iād highly recommend checking out ā excellent module collection if you havenāt already. My only gripe with these modules is that they likely wonāt work out-of-the-box with most frontend toolchains like or . async & await Sindre Sorhus promise-fun create-react-app rollup Here are a few of the most useful gems which stick out for working with promises and async-style code in Node: - Promisify a callback-style function. pify There are a lot of ways to convert functions from old-school callback-style to Promise-style, but Iāve found to be the best. Itās tiny and has some niceties like automatic method binding that the built-in is lacking. pify util.promisify - Map over promises concurrently. p-map Concurrency is great, but most of the time you want to set a practical limit on parallelism whether it be throttling network bandwidth or compute resources. This is where really shines. I use it 99% of the time as a drop-in replacement for , which doesnāt support limiting parallelism. p-map Promise.all(ā¦) Before I was aware of , I created my own version , but you should use as itās better. š p-map async-await-parallel p-map - Retry a promise-returning or async function. p-retry I generally wrap any HTTP requests and external service calls with to add a basic level of robustness to them. Combined with , you can process large batches of external requests with controlled parallelism without having to worry too much about an occasional transport error, socket hang-up, or server timeout. p-retry p-map - Timeout a promise after a specified amount of time. p-timeout Alongside , is a must for robustly working with third-party APIs and services. You can also specify an optional fallback, as oftentimes returning is better than hanging indefinitely or returning after an inordinate amount of time. p-retry p-timeout something or - Memoize the results of an async function via an . p-cache p-memoize LRU cache The aim of many of these Promise utilities reminds me a lot of architecting robust , where every external dependency can be treated with a common interface supporting retrys, timeouts, caching, circuit breakers, fallbacks, etc. microservices Graceful degradation of functionality is generally preferable to overwhelming the system or not responding at all, so if youāre not too familiar with microservices, check them out and see if their design decisions can help improve your Promise handling abilities as well. Scraping There are a lot of great scraping utilities out there, some of which operate on raw HTML like , and some of which simulate a full browser environment like . What you decide to use really depends on your use case, as working with raw HTML is a lot quicker and more lightweight, whereas automating a headless browser is more robust at the cost of being heavier to get started. cheerio puppeteer - Fast, flexible, and lean implementation of core designed specifically for the server. cheerio jQuery Cheerio is really great for quick & dirty web scraping where you just want to operate against raw HTML. It provides a robust jQuery-like syntax for traversing & manipulating HTML documents. Cheerio pairs particularly well with below for fetching remote HTML documents. request-promise-native - Headless Chrome Node API puppeteer Unlike cheerio, puppeteer is a wrapper for automating headless chrome instances, which is really useful for working with modern JS-powered SPAs. Since youāre working with Chrome itself, it also has best-in-class support for parsing / rendering / scripting conformance. Headless Chrome is still relatively new, but it will likely phase out older approaches such as in the years to come. PhantomJS If you need to faithfully scrape websites, automate web-based workflows, or capture screenshots, is a clear winner that will only become more popular with time. puppeteer Node.js Load environment variables from and ensure theyāre all present. dotenv-safe - .env This module extends the hugely popular module to enforce the existence of expected environment variables via a file. Like the original, it provides fast, secure, and robust environment variable support for Node. dotenv .env.example It also plays well with Zeitās deployments with the option set in . now.sh ādotenvā: true now.json and - Simplified HTTP request client. request request-promise-native Making HTTP requests is an extremely common operation, and my goto module here is which wraps the original module with native ES6 promise support. 95% of the time I want to await the result of a promisified HTTP request. The other 5% of the time I want to work with the response stream directly, in which case I use the underlying module, foregoing Promise support. request-promise-native request request For robustness, I will oftentimes wrap calls in some combination of , , and . request-promise-native p-retry p-timeout p-cache Itās also worth mentioning as a newer alternative to with promise support baked in, although I havenāt used it much personally. got request - Template engine consolidation library for Node. consolidate Consolidate is great for handling any type of backend templating (emails, tweets, raw html, etc.). I generally use as my templating engine of choice, but no matter what, I always wrap my template usage in , because it provides a simple & consistent interface to templating regardless of the template engine you decide to use under the hood. handlebars consolidate For example, I used consolidate in to render the boilerplateās templates with library-specific variables. create-react-library - A better . execa child_process Extremely useful if you need to run a shell command or spawn a child process in general. - A better with additional methods and Promise support. fs-extra fs Itās rare that I find myself using directly anymore. Try and you wonāt look back. fs fs-extra Math (Data-Driven Documents) is a popular frontend library for data visualization and animation. It also contains some of the best for common math operations that I find myself consistently choosing over alternative modules. D3 standalone packages āāGenerate random numbers from various distributions. d3-random When doesnāt cut it, give a try. It supports sampling from different common distributions, including uniform, normal, and exponential. Math.random d3-random - Easing functions for smooth animations. d3-ease Image Credit: d3-ease - Interpolate numbers, colors, strings, arrays, objects, whatever! d3-interpolate This module provides a variety of interpolation methods for blending between two arbitrary values. Values may be numbers, colors, strings, arrays, or even deeply-nested objects. Testing - Awesome JS test runner. ava Itās not surprising that my go-to for unit test runner for Node.js is yet another tool created by Sindre Sorhus. Ava is a newer unit test runner that takes a lot of what was good about , , and other JS test runners, and bundles it all together into a quality project with sensible defaults that ājust worksā. mocha tape chai Itās worth noting that Avaās tests are run in parallel by default, which you can disable at the file-level for use cases like database testing where the order your unit tests run may be important. Image Credit: ava - HTTP mocking and expectations library. nock Nock is great for testing modules that perform HTTP requests in isolation. If your Node module makes HTTP requests and you want to provide proper unit testing, then is the way to go. nock - Function spies, stubs and mocks for JS testing. sinon Sinon is a very useful utility library for writing isolated tests by taking advantage of dependency injection. It should be a part of every Node developerās tool belt. Wrapping Up I hope youāve found this breakdown helpful, even if itās just learning about one quality module that you werenāt aware of before. I know a lot of aspiring and seasoned developers alike who end up rolling their own solutions to common problems, which can be a useful practice in & of itself, but itās also good to know when there are quality, existing solutions you should be using instead of constantly reinventing the wheel. The size & scope of NPMās module library is unprecedented, and imho itās one of JavaScriptās biggest advantages compared with other programming languages. The better you become at taking advantage of npm modules, the faster and more productive youāll be as a developer. Higher-order āsoftā skills like this are one of the hallmarks of becoming a . mythical 10x programmer Have any favorite npm modules I left out? Let me know by sharing your favorite modules in the comments! ā¤ļø Before youĀ goā¦ If you liked this article, click the š below, and share it with others so they can enjoy it as well.