✅ 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-noderuns TypeScript without compiling but has no reload. -
ts-node-devadds auto-reload but doesn't work well withimport/exportand ESM. -
tsxis 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
awaitat 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.
Top comments (0)