DEV Community

Jonathan Creamer
Jonathan Creamer

Posted on • Originally published at jonathancreamer.com on

Running Typescript scripts in node using esbuild

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...

[

Running Typescript programs with babel-node aka how does babel register work

Running Typescript programs on demand with babel-node basically uses babel register, but how does babel register work? This post will detail it.

Running Typescript scripts in node using esbuildJonathan CreamerJonathan Creamer

Running Typescript scripts in node using esbuild
](https://www.jonathancreamer.com/running-programs-with-babel-node/)

However, I recently discovered that ESBuild has a similar mechanism to babel-node called esbuild-runner.

[

esbuild-runner

Super-fast on-the-fly transpilation of modern JS, TypeScript and JSX using esbuild. Latest version: 2.2.1, last published: 10 months ago. Start using esbuild-runner in your project by running npm i esbuild-runner. There are 13 other projects in the npm registry using esbuild-runner.

Running Typescript scripts in node using esbuildnpm

Running Typescript scripts in node using esbuild
](https://www.npmjs.com/package/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...

Running Typescript scripts in node using esbuild

I hope to employ esbuild-runner in some more local developer tooling so developers don't have to pre-compile or build their tools.

Top comments (0)