Skip to content

Getting started

Prerequisites

Before you can start using tsx, ensure that you have Node.js installed. tsx is designed to be compatible with all maintained versions of Node.js.

Quickstart

tsx can be executed with npx—a tool to run npm packages without installing them.

In your command-line, simply pass in a TypeScript file you'd like to run. It's that simple!

sh
npx tsx ./script.ts

Project installation

To install tsx as a project development dependency, run the following command in your project directory:

sh
$ npm install -D tsx
sh
$ pnpm add -D tsx
sh
$ yarn add -D tsx

Using tsx

Once installed, you can invoke it with your package manager while in the project directory:

sh
$ npx tsx ./file.ts
sh
$ pnpm tsx ./file.ts
sh
$ yarn tsx ./file.ts

Using it in package.json#scripts

Project commands are usually organized in the package.json#scripts object.

In the scripts object, you can reference tsx directly without npx:

js
// package.json
{
    "scripts": {
        "start": "tsx ./file.ts"
    }
}

Global installation

If you want to use tsx anywhere on your computer (without npx), install it globally:

sh
$ npm install -g tsx
sh
$ pnpm add -g tsx
sh
Yarn 2 doesn't support global installation
https://yarnpkg.com/migration/guide#use-yarn-dlx-instead-of-yarn-global

This allows you to call tsx directly:

sh
tsx file.ts