For the past couple of years, the main way to run scripts written in TypeScript has been with ts-node
. However, now we have something faster and more modern - esbuild-runner
or esr
for short.
It's very fast and very easy to start using today.
š”Tip
esr makes it easy to run arbitrary code or tests without needing to build your whole project. It's a great way to improve your development workflow.
How to Use
In 2 mins or less, let me show you exactly how to use it:
yarn init -y
- create a new projectyarn add -D esbuild esbuild-runner
- add dependenciesecho "console.log('hello world')" > hello-world.ts
- create a scriptyarn esr hello-world.ts
- run your script
After that, you should see the following output in your terminal:
yarn run v1.22.15
$ /esr-test/node_modules/.bin/esr hello-world.ts
hello world
Done in 0.23s
Lightning fast!
And with that new knowledge, you can now migrate your project's scripts over from Bash to TypeScript. Woohoo!