TSX vs. TS-Node and Nodemon

Which NodeJS runner is fastest for typescript?

Lincoln W Daniel
Published in ModernNerd Codeย โ€ขย 
3 min read
TypeScript

A developer asked the following question on StackOverflow:

How to watch and reload ts-node when TypeScript files change

This article is my answer to that question, with a clear comparison to the leading alternative, tsx. I also include my tsconfig.json and the exact packages I'm using in this setup.

In 2024, ts-node with nodemon is consistently 3 times faster than tsx in a large project, such as the one I use to run ManyStories.com and OurTransfers.com for over a million visitors and customers per year.

I wanted tsx to be faster since it's so much simpler, but it unfortunately is not. I had to change to ts-node after a couple of weeks of wasted time waiting half a minute after every code change for tsx to recompile my code.

I ran the following two scripts:

1"scripts": {
2	"dev-server-tsx": "date && NODE_ENV=development ENV_IS_DEV=true FORCE_COLOR=1 tsx watch --clear-screen=false ./src/serverInstance.ts",
3
4    "dev-server-nodemon": "date && NODE_ENV=development ENV_IS_DEV=true FORCE_COLOR=1 nodemon ./src/serverInstance.ts",
5}

with these packages:

"nodemon": "^3.1.7",
"ts-node": "^10.9.2",
"tsconfig-paths": "^4.2.0",
"tslib": "^2.8.0",
"tsx": "^4.19.1",

Results:

  • tsx consistently takes between 32-35 seconds to start and restart

  • ๐Ÿ† nodemon (with ts-node) consistently took around 11-12 seconds to start, and only a few seconds for restarts.

The amount of time tsx takes for restarting on code changes makes it impossible to be productive when debugging, wherein you need to make frequent changes to figure out the root cause of an issue.

If you'd like to use ts-node with nodemon, you can learn more about how this works from this Github pull request on the Nodemon project: https://github.com/remy/nodemon/pull/1552

Also, here's my setup for my tsconfig.json:

1{
2    // This is an alias to @tsconfig/node16: https://github.com/tsconfig/bases
3    "extends": "ts-node/node16/tsconfig.json",
4
5    // Most ts-node options can be specified here using their programmatic names.
6    "ts-node": {
7      "require": ["tsconfig-paths/register"],
8
9      // It is faster to skip typechecking.
10      // Remove if you want ts-node to do typechecking.
11      "transpileOnly": true,
12  
13      "files": true,
14  
15      "compilerOptions": {
16        // compilerOptions specified here will override those declared below,
17        // but *only* in ts-node.  Useful if you want ts-node and tsc to use
18        // different options with a single tsconfig.json.
19        "module": "commonjs",
20      }
21    },
22    "compilerOptions": {
23	  // Other compiler options
24      "target": "esnext",
25      "baseUrl": ".",
26      "paths": {
27        "@/shared/*": ["src/shared/*"],
28        "@/utils/*": ["src/utils/*"],
29        "@/constants/*": ["src/lib/constants/*"],
30        "@/envConfig": ["src/config/config"],
31        
32        "@/globals": ["src/lib/globals2"],
33        "@/lib/*": ["src/lib/*"],
34        "@/api/*": ["src/api/*"],
35        "@/src/*": ["src/*"]
36      }
37    },
38    "exclude": [
39      "node_modules",
40      "static",
41      "**/*.spec.ts"
42    ],
43    "include": [
44      "**/*.ts",
45      "**/*.tsx"
46    ]
47  }

TypeScript
NodeJs
Server
Software Development
Coding