This week I was working on a project that reads 6.4 MB of text files (the complete English Bible), does some processing and computation, and then outputs JSON data. You can see result of that work on GitHub.
In times past, I’ve felt pressure to reach for a “proper scripting language” like Python or a more performant one like Go. But I feel like we’ve reached the point where Node.js is a great choice for scripting.
- The ecosystem is huge. There are over one million npm packages, so the chances are good that there is a solution available for whatever problem you have. And thanks to JS being everywhere, there are countless guides to adding dependencies to your project.
- Node.js is readable. Thanks to JS’ async/await and sync functions from Node.js’ standard libraries, writing a script that reads multiple files/directories and then writes to others is pretty straightforward. No more chaining callbacks!
- Node.js supports ESM. Node.js supports ES modules with either the
type: moduleflag in
.mjsextension. Maybe this is a bigger deal for me personally, but the ability to import and export modules without needing to think about
module.exportsis pretty nice.
- Node.js is fast. That project I mentioned at the top? The Node.js script that I wrote (which was not optimized for performance) ran in less than a second. 6.4 MB in < 1 second! I’m not saying that Node.js is the fastest option, but for your typical scripting needs: it’s more than fast enough.
I’m not arguing that everyone should be using Node.js for scripting, nor that it is the best solution for every problem in every environment. And if you prefer Rust or Go or Ruby or WhatEver, go for it!