TypeScript Execute (tsx): Node.js enhanced with esbuild to run TypeScript & ESM files
—
tsx provides a powerful command-line interface for executing TypeScript files directly without compilation, with support for watch mode, REPL, and various execution options.
Execute TypeScript files directly from the command line.
tsx [options] <script> [script-args...]Options:
--no-cache: Disable transformation caching--tsconfig <path>: Custom tsconfig.json path--input-type <type>: Specify input type for evaluation--test: Run Node.js built-in test runner--version, -v: Show version--help, -h: Show helpUsage Examples:
# Run a TypeScript file
tsx server.ts
# Run with custom tsconfig
tsx --tsconfig ./custom-tsconfig.json app.ts
# Run with arguments passed to script
tsx script.ts --arg1 value1 --arg2 value2
# Disable caching
tsx --no-cache slow-script.tsMonitor files for changes and automatically restart execution.
tsx watch [options] <script> [script-args...]Additional Watch Options:
--clear-screen: Clear screen on restart (default: true)--no-clear-screen: Disable screen clearing on restart--include <patterns>: Additional paths & globs to watch--exclude <patterns>: Paths & globs to exclude from watching--ignore <patterns>: Paths & globs to exclude from being watched (deprecated: use --exclude)Usage Examples:
# Basic watch mode
tsx watch server.ts
# Watch with specific include/exclude patterns
tsx watch --include "src/**/*.ts" --exclude "**/*.test.ts" app.ts
# Disable screen clearing
tsx watch --no-clear-screen server.tsExecute TypeScript code directly from command line.
tsx -e <code>
tsx --eval <code>
tsx -p <code>
tsx --print <code>Usage Examples:
# Execute TypeScript code
tsx -e "console.log('Hello from TypeScript!')"
# Print expression result
tsx -p "Math.PI * 2"
# Execute with imports
tsx -e "import fs from 'fs'; console.log(fs.readdirSync('.'))"Interactive TypeScript REPL with enhanced features.
tsxThe REPL provides:
Usage Examples:
# Start REPL
tsx
# In REPL:
> const name: string = "tsx"
> console.log(`Hello ${name}!`)
> import fs from 'fs'
> fs.readdirSync('.')Integration with Node.js built-in test runner for executing TypeScript test files.
tsx --test [test-patterns...]Features:
.test.ts, .test.js, and other test file patterns--no-cache and --tsconfigUsage Examples:
# Run all TypeScript test files
tsx --test
# Run specific test patterns
tsx --test "**/*.test.ts"
# Run tests with custom tsconfig
tsx --test --tsconfig ./test-tsconfig.json
# Run tests with caching disabled
tsx --test --no-cache
# Run tests with watch mode
tsx watch --test
# Run tests from specific directory
tsx --test "./tests/**/*.test.ts"Control tsx behavior through environment variables.
TSX_DISABLE_CACHE=1 # Disable transformation caching
TSX_TSCONFIG_PATH=path # Custom tsconfig.json pathUsage Examples:
# Run with caching disabled
TSX_DISABLE_CACHE=1 tsx script.ts
# Use custom tsconfig via environment
TSX_TSCONFIG_PATH=./my-config.json tsx app.tstsx properly handles process signals and forwards them to child processes.
Supported Signals:
SIGINT (Ctrl+C): Graceful shutdownSIGTERM: Termination requesttsx seamlessly integrates with Node.js features:
Usage with Node.js flags:
# Use Node.js flags with tsx
node --inspect tsx script.ts
node --experimental-modules tsx app.tsInstall with Tessl CLI
npx tessl i tessl/npm-tsx