✅ Commit
chore: use tsx for development
🛠️ Command
npm install --save-dev tsx
📄 package.json (scripts)
"scripts": {
"dev": "tsx watch src/server.ts"
}
▶️ Run the server
npm run dev
Why we use tsx
instead of ts-node
or ts-node-dev
-
ts-node
runs TypeScript without compiling but has no reload. -
ts-node-dev
adds auto-reload but doesn't work well withimport/export
and ESM. -
tsx
is fast, needs no config, and supportsimport
,await
, and"type": "module"
out of the box.
We use tsx
because it's simple, modern, and fully compatible with the current JavaScript module standard (ESM).
What is ESM?
ESM = ECMAScript Modules
It is the modern way to import and export code in JavaScript and TypeScript.
Key features:
- Uses
import
/export
- Requires
"type": "module"
inpackage.json
- Allows
await
at the top level (no need for async functions) - Works in both Node.js and browsers
Example (ESM)
import express from "express";
export default app;
ESM is now the standard. tsx
supports it without extra setup.