Bun as a scripting language
In case it isn’t clear from the name, JavaScript is a scripting language. Although it was built for scripting in web pages, nowadays we have the ability to use it for general scripting as well. One approach that I am becoming quite fond of is to use Bun as a script runner, writing JavaScript or TypeScript that utilizes Bun’s $
shell feature.
Add a shebang to the start of the file e.g. #!/usr/bin/env bun
, make your .js
or .ts
file executable, and then you can just run it like you would a shell script. Or compile it to a single executable, but I don’t think that’s necessary in this context. You don’t even need to initialize npm in your project, so you can avoid bulking up your repo with additional npm related files and directories.
Instead of a Makefile
or package.json
, just write one or more Bun scripts that do what you need. This approach is proving useful in projects of any language, not just in JavaScript projects.