TypeScript execution environment and REPL for Node.js with source map support
—
Command-line interfaces for executing TypeScript files and interactive REPL sessions with comprehensive configuration options and execution modes.
Primary command-line interface with full TypeScript execution and REPL support.
// Available as ts-node binary
// Executes TypeScript files or starts interactive REPL
// Usage: ts-node [options] [script] [arguments]Usage Examples:
# Execute TypeScript file
ts-node script.ts
# Start interactive REPL
ts-node
# Execute with compiler options
ts-node --compiler-options '{"strict":true}' script.ts
# Transpile-only mode for faster execution
ts-node --transpile-only script.ts
# Execute inline TypeScript code
ts-node --eval "console.log('Hello, TypeScript!')"CLI that changes working directory before execution.
// Available as ts-node-cwd binary
// Changes to script directory before execution
// Usage: ts-node-cwd [options] <script> [arguments]Usage Examples:
# Execute script from its directory
ts-node-cwd /path/to/project/script.ts
# Useful for scripts that expect to run from their directory
ts-node-cwd ../other-project/build-script.tsCLI with native ECMAScript module support.
// Available as ts-node-esm binary
// Enables ESM support automatically
// Usage: ts-node-esm [options] [script] [arguments]Usage Examples:
# Execute TypeScript with ESM support
ts-node-esm esm-script.ts
# Start ESM REPL
ts-node-esm
# With experimental specifier resolution
ts-node-esm --experimental-specifier-resolution=node script.tsScript execution without REPL functionality for production environments.
// Available as ts-node-script binary
// Script-only execution, no REPL
// Usage: ts-node-script [options] <script> [arguments]Usage Examples:
# Execute script without REPL fallback
ts-node-script production-script.ts
# Faster startup for scripts that don't need REPL
ts-node-script --transpile-only batch-processor.tsFast transpile-only CLI that skips type checking for maximum performance.
// Available as ts-node-transpile-only binary
// Forces transpileOnly: true mode
// Usage: ts-node-transpile-only [options] [script] [arguments]Usage Examples:
# Fast execution without type checking
ts-node-transpile-only large-script.ts
# Development mode with fast iteration
ts-node-transpile-only dev-server.tsDeprecated alias for ts-node-script.
// Available as ts-script binary (deprecated)
// Alias for ts-node-script
// Usage: ts-script [options] <script> [arguments]
// Note: Use ts-node-script insteadUsage Examples:
# Deprecated - use ts-node-script instead
ts-script script.ts
# Recommended replacement
ts-node-script script.tsOptions available across all CLI binaries.
# Compilation Options
--transpile-only # Skip type checking (faster)
--type-check # Force type checking
--compiler-host # Use compiler host API
--files # Load files from tsconfig.json
# Project Options
--project <path> # Path to tsconfig.json
--skip-project # Skip project config resolution
--cwd <path> # Working directory
# Compiler Options
--compiler <name> # TypeScript compiler package
--compiler-options <json> # JSON compiler options
--transpiler <name> # Alternative transpiler
# SWC Integration
--swc # Use SWC transpiler
# Output Options
--pretty # Pretty diagnostic formatter
--emit # Emit compiled files
--log-error # Log errors to stderr
# Ignore Options
--ignore <pattern> # Ignore file patterns
--skip-ignore # Skip ignore patterns
--ignore-diagnostics <codes> # Ignore diagnostic codes
# ESM Options (ts-node-esm)
--experimental-specifier-resolution <mode> # 'node' or 'explicit'
--experimental-ts-import-specifiers # Allow .ts in imports
# Execution Options
--eval <code> # Execute inline code
--print <code> # Execute and print result
--require <module> # Require modules before execution
# REPL Options
--interactive # Force interactive mode
--experimental-repl-await # Enable top-level await in REPL
# Debug Options
--show-config # Show resolved configuration
--help # Show help message
--version # Show version information# Development setup with fast compilation
ts-node --transpile-only \
--compiler-options '{"target":"ES2020","strict":false}' \
--ignore 'node_modules' \
src/dev-server.ts
# Production-like setup with full type checking
ts-node --type-check \
--pretty \
--files \
--project tsconfig.prod.json \
src/app.ts
# ESM project with path mapping
ts-node-esm --experimental-specifier-resolution=node \
--compiler-options '{"baseUrl":".","paths":{"@/*":["src/*"]}}' \
src/index.ts
# Debug mode with comprehensive output
ts-node --show-config \
--log-error \
--pretty \
--compiler-options '{"traceResolution":true}' \
debug-script.ts{
"scripts": {
"start": "ts-node src/index.ts",
"start:fast": "ts-node-transpile-only src/index.ts",
"start:esm": "ts-node-esm src/index.ts",
"dev": "ts-node --transpile-only --watch src/dev-server.ts",
"build": "ts-node build-script.ts",
"test": "ts-node --transpile-only test/runner.ts",
"repl": "ts-node",
"debug": "ts-node --show-config --log-error src/index.ts"
}
}#!/bin/bash
# start.sh - Environment-aware startup script
if [ "$NODE_ENV" = "development" ]; then
exec ts-node-transpile-only src/index.ts
elif [ "$NODE_ENV" = "production" ]; then
exec ts-node --type-check --files src/index.ts
else
exec ts-node src/index.ts
fiFROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
# Use appropriate CLI for container environment
CMD ["ts-node-script", "--transpile-only", "src/index.ts"]{
"apps": [{
"name": "my-app",
"script": "ts-node-script",
"args": ["--transpile-only", "src/index.ts"],
"watch": ["src"],
"ignore_watch": ["node_modules", "logs"],
"env": {
"NODE_ENV": "development"
}
}]
}// Custom CLI wrapper
import { main, BootstrapState } from "ts-node/dist/bin";
const customBootstrap: BootstrapState = {
parseArgvResult: {
// Custom argument parsing
},
phase2Result: {
// Custom phase 2 configuration
}
};
// Start custom CLI
main(['--transpile-only', 'script.ts'], customBootstrap);// conditional-cli.js
const { spawn } = require('child_process');
const fs = require('fs');
// Choose CLI based on project structure
const hasTsConfig = fs.existsSync('tsconfig.json');
const packageJson = JSON.parse(fs.readFileSync('package.json', 'utf8'));
const isESM = packageJson.type === 'module';
let command = 'ts-node';
let args = [];
if (isESM) {
command = 'ts-node-esm';
args.push('--experimental-specifier-resolution=node');
}
if (!hasTsConfig) {
args.push('--transpile-only');
}
args.push('src/index.ts');
spawn(command, args, { stdio: 'inherit' });# Use specific TypeScript version
ts-node --compiler typescript@4.9.5 script.ts
# Use fork of TypeScript compiler
ts-node --compiler @my-org/typescript script.ts
# Use nightly TypeScript build
ts-node --compiler typescript@next script.ts# Monitor CLI performance
time ts-node --show-config script.ts
# Memory usage monitoring
node --max-old-space-size=4096 ts-node script.ts
# CPU profiling
node --prof ts-node script.ts
node --prof-process isolate-*.log > profile.txt# Graceful error handling in scripts
set -e # Exit on error
# Capture ts-node errors
if ! ts-node script.ts 2>errors.log; then
echo "TypeScript compilation failed:"
cat errors.log
exit 1
fi
# Ignore specific diagnostic codes
ts-node --ignore-diagnostics 2307,2345 script.tsInstall with Tessl CLI
npx tessl i tessl/npm-ts-node