tsx
tsx is a TypeScript execute tool that lets you run TypeScript files directly in Node.js without a compilation step, using esbuild for near-instant transformatio…
Installation
npm install -D tsx
yarn add -D tsx
pnpm add -D tsx
Import
// Used as CLI: tsx script.ts
Quick Example
// Run TypeScript directly: // npx tsx src/script.ts // Watch mode: // npx tsx watch src/server.ts // With Node.js flags: // node --import tsx src/app.ts
About tsx
tsx is a TypeScript execute tool that lets you run TypeScript files directly in Node.js without a compilation step, using esbuild for near-instant transformation. tsx serves as a modern replacement for ts-node, providing significantly faster startup times because esbuild compiles TypeScript to JavaScript orders of magnitude faster than the TypeScript compiler. tsx supports ESM and CommonJS modules, path aliases from tsconfig.json, watch mode that re-runs your script on file changes, and works with Node.js's built-in test runner and --inspect flag for debugging. The tool operates by registering itself as a module loader that intercepts .ts, .tsx, .mts, and .cts file imports and transforms them on the fly using esbuild. tsx does not perform type checking — it only strips types and transforms syntax, matching esbuild's compilation model where type errors are caught separately by tsc or IDE integration. This separation of concerns (fast execution vs. thorough type checking) follows the modern TypeScript development pattern. tsx is particularly useful for running scripts, development servers, database migrations, and seed files written in TypeScript without maintaining a separate build step.
Quick Facts
| Package | tsx |
| Category | Build Tool |
| Weekly Downloads | 8M+ |
| License | MIT |
| Install | npm install -D tsx |
Related Packages
ts-node is a TypeScript execution engine and REPL for Node.js that transforms TypeScript to JavaScri…
esbuild is an extremely fast JavaScript and TypeScript bundler and minifier written in Go that is 10…
TypeScript is a strongly typed programming language that builds on JavaScript, adding static type de…
SWC (Speedy Web Compiler) is a Rust-based JavaScript/TypeScript compiler that provides a drop-in rep…
Vite is a next-generation frontend build tool created by Evan You (creator of Vue.js) that provides …
Browse npm Packages by Category
Explore our reference of 200 popular npm packages with install commands, examples, and quick-start guides.