docs/getting-started.md
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.
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!
npx tsx ./script.ts
To install tsx as a project development dependency, run the following command in your project directory:
::: code-group
$ npm install -D tsx
$ pnpm add -D tsx
$ yarn add -D tsx
:::
tsxOnce installed, you can invoke it with your package manager while in the project directory:
::: code-group
$ npx tsx ./file.ts
$ pnpm tsx ./file.ts
$ yarn tsx ./file.ts
:::
package.json#scriptsProject commands are usually organized in the package.json#scripts object.
In the scripts object, you can reference tsx directly without npx:
// package.json
{
"scripts": {
"start": "tsx ./file.ts"// [!code highlight]
}
}
If you want to use tsx anywhere on your computer (without npx), install it globally:
::: code-group
$ npm install -g tsx
$ pnpm add -g tsx
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:
tsx file.ts