Getting started
Run your first TypeScript file with tsx and see its output in the terminal.
Prerequisites
Install Node.js with npm, and check the supported Node.js requirements. Open a terminal in the directory where you want to keep this example.
Quickstart
Create this file in that directory:
script.ts
const message: string = 'Hello from tsx!'
console.log(message)Run it from the same directory:
npx tsx ./script.tsIf npm asks to download tsx, confirm to continue. The script prints:
Hello from tsx!Import another TypeScript file
tsx also loads TypeScript files imported by your script. Create this file beside it:
greeting.ts
export const greet = (name: string) => `Hello, ${name}!`Replace your original script with:
script.ts
import { greet } from './greeting.ts'
console.log(greet('world'))Run the same command:
npx tsx ./script.tsIt prints:
Hello, world!You have now run TypeScript without a separate build step. For repeated use, install tsx in your project.
Next steps
Continue with project setup and package scripts. The installation guide also covers global commands. Use the TypeScript configuration guide to add type checking separately.
Building a library or CLI that loads TypeScript files written by its users? See Load TypeScript in your tool.
Looking for installation instructions?
Installation instructions have moved. Continue to project installation, package scripts, or global installation.
