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 (3)

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

Visualizing Promises and Async/Await 🤯

async await

☝️ Check out this all-time classic DEV post