TypeScript Execute (tsx)
tsx runs TypeScript and JavaScript in Node.js, with CommonJS and ECMAScript module (ESM) interoperability and watch mode in one CLI. Use it for scripts, application development, and tools that load TypeScript files.
Use npx tsx where you would run node:
node file.js→↓
npx tsx file.tsFollow Getting started for a complete example with setup and output. You can also pass Node.js flags and script arguments.
Features
Seamless TypeScript execution
Run a .ts, .mts, .cts, or .tsx file directly. tsx transforms files as they load, so you do not need a separate build step or the TypeScript compiler to execute them. Start with a complete first-run example.
Add type checking and a distributable build as separate steps when your project needs them.
CommonJS and ESM interoperability
Load ESM dependencies from CommonJS and run TypeScript in either module system. Synchronous loading still requires synchronously executable modules; see CommonJS and ES modules for the interop rules and limits.
Watch mode
Use watch mode to rerun a script when its imported files change. The watch reference provides a complete example and expected output.
Load TypeScript in your own tool
Let users of your library, CLI, or plugin system write config files and plugins in TypeScript. tsImport() loads a file through Node.js's module loader without enabling tsx for the rest of your application:
import path from 'node:path'
import { pathToFileURL } from 'node:url'
import { tsImport } from 'tsx/esm/api'
const configUrl = pathToFileURL(path.resolve('my-tool.config.ts')).href
const loaded = await tsImport(configUrl, import.meta.url)See Load TypeScript in your tool for a complete example, synchronous loading, and other integrations.
Find your next step
| You want to… | Start here |
|---|---|
| Run your first TypeScript file | Getting started |
| Pass arguments or Node.js flags | CLI usage |
| Run TypeScript tests | Testing |
| Set breakpoints in your editor | VS Code debugging |
| Let your tool load users' TypeScript configs or plugins | Load TypeScript in your tool |
About the project
tsx combines TypeScript transformation, CommonJS and ESM integration, and a development CLI in one package. It uses esbuild to transform code and runs it in your installed Node.js runtime.
tsx project development relies on user donations. Funding supports ongoing maintenance and development.
If your company uses tsx and would like to support the project, consider sponsoring us. In return, we'll display your logo and link.
