DEV Community

Jaruwat Thongchana
Jaruwat Thongchana

Posted on

Use tsx instead of nodemon

If you use typescript, nodemon and ts-node for development.
You'll notice that it takes a while to recompile the code when it changes.

tsx is a Typescript execute which blazing fast ⚡️ with esbuild.

Installation

I prefer use pnpm but you can use npm, yarn, ...etc.

pnpm add -D tsx
Enter fullscreen mode Exit fullscreen mode

Now you can uninstall nodemon and ts-node.

pnpm remove nodemon ts-node
Enter fullscreen mode Exit fullscreen mode

Add script tsx watch [file/folder] in the package.json.

{
  "name": "use-tsx",
  "version": "1.0.0",
  "main": "index.ts",
  "scripts": {
    "dev": "tsx watch src",
  },
  "devDependencies": {
    "@types/node": "^18.7.18",
    "tsx": "^3.9.0",
    "typescript": "^4.8.3",
  }
}
Enter fullscreen mode Exit fullscreen mode

Let's start.

pnpm dev
Enter fullscreen mode Exit fullscreen mode

refs:

Top comments (7)

Collapse
 
ritikbanger profile image
Ritik Banger • Edited

I would recommend swc with ts-node. Its super-fast.

Collapse
 
rennycat profile image
Jaruwat Thongchana

Yes in some cases, but tsx is the most compatible.
So you can see in ts-runtime-comparison

Collapse
 
ritikbanger profile image
Ritik Banger

When you look at the size comparison plus bugs, you can easily know which one is preferable.

Image description

Thread Thread
 
ivankleshnin profile image
Ivan Kleshnin • Edited

10 bug issues is a negligible number and install size difference of few Mbs does not matter on BE at all. TSX is the most reliable & feature-rich. Superior to those alternatives.

Thread Thread
 
ritikbanger profile image
Ritik Banger

It's not a few MBs difference. It is 1 MB v/s 10 MB. Bundle size matters in speed/performance.

Thread Thread
 
josepur profile image
José Paulo Urives Rosa • Edited

TSX being built under esbuild makes it faster and more feature-rich. You can argue on the library's size but it's a dev dependency and the bundle size of your application is considerably smaller than the other ones. Your 1 mb library will give you a bad dev experience and compile a 30mb bundle. The 10mb library will have the most cutting edge features and will compile a 10mb bundle.

Collapse
 
jonathanjumper profile image
Jonathan

Thanks man, i was getting crazy over this tsx, nodemon, ts-node, pnpm, npm
it's crazy, so many years, so. many thing incompatible