Skip to content

Commit 21688d0

Browse files
docs: improve explanation
1 parent 1c831fe commit 21688d0

File tree

1 file changed

+41
-19
lines changed

1 file changed

+41
-19
lines changed

README.md

+41-19
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,45 @@ _TypeScript Execute (tsx)_: The easiest way to run TypeScript in Node.js
3030
</p>
3131

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

35-
tsx is for you if you want:
36-
- A command to _just run_ TypeScript code without configuration
37-
- Something so fast it's unnoticeable
38-
- Seamless integration across ESM and CJS dependencies
35+
<table>
36+
<tr>
37+
<th>Before</th>
38+
<th>After</th>
39+
</tr>
40+
<tr>
41+
<td>
42+
43+
```sh
44+
node file.js
45+
```
46+
47+
</td>
48+
<td>
49+
50+
```sh
51+
tsx file.js
52+
```
53+
54+
</td>
55+
</tr>
56+
</table>
3957

40-
If you're getting the following error, give tsx a try!
58+
59+
Use it to enhance your Node.js experience:
60+
- _Just run_ TypeScript code without configuration
61+
- Seamless integration between CommonJS and ES Modules
62+
63+
You'll never get the following error again:
4164

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

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

5073
```sh
5174
npx tsx ./script.ts
@@ -86,26 +109,25 @@ npm install --global tsx
86109
Then, you can call `tsx` directly:
87110

88111
```sh
89-
tsx ...
112+
tsx file.ts
90113
```
91114

92-
## Usage
93-
94-
### tsx is a Node.js wrapper
115+
Now you can replace `node ...` with `tsx ...` in all your commands!
95116

96-
_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).
117+
## Usage
97118

98-
```sh
99-
# --no-warnings is a Node.js flag
100-
tsx --no-warnings ./file.ts
101-
```
119+
### Swap `node` out for `tsx`
102120

103-
### Run TypeScript / ESM / CJS module
121+
_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.
104122

105-
Pass in a file to run:
123+
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).
106124

107125
```sh
108-
tsx ./file.ts
126+
# Old command
127+
node --no-warnings --env-file=.env ./file.js
128+
129+
# New command
130+
tsx --no-warnings --env-file=.env ./file.js
109131
```
110132

111133
#### Custom `tsconfig.json` path

0 commit comments

Comments
 (0)