Running Typescript scripts in node using esbuild
Typescript is hands down my favorite way to write Javascript these days, but sometimes when I just want to run a quick JS script to do something, I'll still reach for node ./foo/script.js
. I'll sometimes reach for babel-node
`, or @babel/register
, but that can be pretty difficult to configure sometimes, and has some perf issues.
It does work though, and I have a post on it...
However, I recently discovered that ESBuild has a similar mechanism to babel-node called esbuild-runner
.
It's SUPER easy to use as well.
> npm i esbuild esbuild-runner
Then, anytime you run a .ts
file, you do...
node -r esbuild-runner/register ./path/to/script.ts
And it's stupid fast...
I hope to employ esbuild-runner
in some more local developer tooling so developers don't have to pre-compile or build their tools.