Skip to content

Commit

Permalink
docs: improve explanation
Browse files Browse the repository at this point in the history
  • Loading branch information
privatenumber authored Apr 3, 2024
1 parent 1c831fe commit 21688d0
Showing 1 changed file with 41 additions and 19 deletions.
60 changes: 41 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,45 @@ _TypeScript Execute (tsx)_: The easiest way to run TypeScript in Node.js
</p>

## About
`tsx` is a CLI command (alternative to `node`) for running TypeScript & ESM in both `commonjs` & `module` package types.
`tsx` is a CLI command you can use just like you would use `node`:

tsx is for you if you want:
- A command to _just run_ TypeScript code without configuration
- Something so fast it's unnoticeable
- Seamless integration across ESM and CJS dependencies
<table>
<tr>
<th>Before</th>
<th>After</th>
</tr>
<tr>
<td>

```sh
node file.js
```

</td>
<td>

```sh
tsx file.js
```

</td>
</tr>
</table>

If you're getting the following error, give tsx a try!

Use it to enhance your Node.js experience:
- _Just run_ TypeScript code without configuration
- Seamless integration between CommonJS and ES Modules

You'll never get the following error again:

```
Error [ERR_REQUIRE_ESM]: require() of ES Module <ESM package> from ./file.js not supported.
Instead change the require of <ESM package> in ./file.js to a dynamic import() which is available in all CommonJS modules.
```

### ⚡️ Quick start
Try it out without setup! Just pass in a TypeScript file:
Try it out without setup using [npx](https://docs.npmjs.com/cli/v8/commands/npx)! Just pass in a TypeScript file:

```sh
npx tsx ./script.ts
Expand Down Expand Up @@ -86,26 +109,25 @@ npm install --global tsx
Then, you can call `tsx` directly:

```sh
tsx ...
tsx file.ts
```

## Usage

### tsx is a Node.js wrapper
Now you can replace `node ...` with `tsx ...` in all your commands!

_tsx_ wraps around Node.js to enhance it with TypeScript support. Because it's a drop-in replacement for `node`, it supports all [Node.js command-line flags](https://nodejs.org/docs/latest-v20.x/api/cli.html).
## Usage

```sh
# --no-warnings is a Node.js flag
tsx --no-warnings ./file.ts
```
### Swap `node` out for `tsx`

### Run TypeScript / ESM / CJS module
_tsx_ is an enhanced version of Node.js. If you have a `node ...` command, you can replace the `node` with `tsx` and it will just work.

Pass in a file to run:
Because it's a drop-in replacement for `node`, it supports all [Node.js command-line flags](https://nodejs.org/docs/latest-v20.x/api/cli.html).

```sh
tsx ./file.ts
# Old command
node --no-warnings --env-file=.env ./file.js

# New command
tsx --no-warnings --env-file=.env ./file.js
```

#### Custom `tsconfig.json` path
Expand Down

0 comments on commit 21688d0

Please sign in to comment.