Skip to content

Commit 84f3ef0

Browse files
authored
docs: tidy CLI overview flag sections and ordering warning (#3176)
1 parent 7410b98 commit 84f3ef0

1 file changed

Lines changed: 36 additions & 129 deletions

File tree

Lines changed: 36 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
last_modified: 2025-11-05
2+
last_modified: 2026-05-28
33
title: Command line interface
44
description: "A comprehensive guide to using Deno's command-line interface (CLI). Learn about running scripts, managing permissions, using watch mode, and configuring Deno's runtime behavior through command-line flags and options."
55
oldUrl:
@@ -9,26 +9,17 @@ oldUrl:
99
- /runtime/manual/tools/
1010
---
1111

12-
Deno is a command line program. The Deno command line interface (CLI) can be
13-
used to run scripts, manage dependencies, and even compile your code into
14-
standalone executables. You may be familiar with some simple commands having
15-
followed the examples thus far. This page will provide a more detailed overview
16-
of the Deno CLI.
12+
The Deno CLI is an all-in-one toolchain for JavaScript and TypeScript projects:
13+
it runs and tests code, formats and lints, manages dependencies, compiles to
14+
standalone binaries, and a lot more. Each subcommand (`run`, `test`, `fmt`,
15+
`compile`, etc.) has its own flags; run `deno help` or
16+
`deno <subcommand> --help` to see them.
1717

18-
The Deno CLI has a number of subcommands (like `run`, `init` and `test`, etc.).
19-
They are used to perform different tasks within the Deno runtime environment.
20-
Each subcommand has its own set of flags and options (eg --version) that can be
21-
used to customize its behavior.
18+
For the complete list of subcommands and flags, see the
19+
[CLI reference](/runtime/reference/cli/). This page covers the patterns you'll
20+
hit early on: how to run code, how to pass arguments, and how to use watch mode.
2221

23-
You can view all of the available commands and flags by running the `deno help`
24-
subcommand in your terminal, or using the `-h` or `--help` flags.
25-
26-
Check out the [CLI reference guide](/runtime/reference/cli/) for a further
27-
documentation on all the subcommands and flags available. We'll take a look at a
28-
few commands in a bit more detail below to see how they can be used and
29-
configured.
30-
31-
## An example subcommand - `deno run`
22+
## Running scripts
3223

3324
You can run a local TypeScript or JavaScript file by specifying its path
3425
relative to the current working directory:
@@ -72,11 +63,22 @@ $ deno run main.ts arg1 arg2 arg3
7263
[ "arg1", "arg2", "arg3" ]
7364
```
7465

66+
For anything beyond a flat list, parse the arguments with
67+
[`parseArgs` from `jsr:@std/cli`](https://jsr.io/@std/cli/doc/parse-args/~/parseArgs)
68+
or
69+
[`parseArgs` from `node:util`](https://nodejs.org/api/util.html#utilparseargsconfig).
70+
7571
## Argument and flag ordering
7672

77-
_Note that anything passed after the script name will be passed as a script
78-
argument and not consumed as a Deno runtime flag._ This leads to the following
79-
pitfall:
73+
:::caution
74+
75+
Anything passed after the script name will be passed as a script argument and
76+
not consumed as a Deno runtime flag. This is a common source of confusion, so
77+
double-check that runtime flags appear **before** the script name.
78+
79+
:::
80+
81+
This leads to the following pitfall:
8082

8183
```shell
8284
# Good. We grant net permission to net_client.ts.
@@ -86,12 +88,7 @@ deno run --allow-net net_client.ts
8688
deno run net_client.ts --allow-net
8789
```
8890

89-
## Common flags
90-
91-
Some flags can be used with multiple related subcommands. We discuss these
92-
below.
93-
94-
### Watch mode
91+
## Watch mode
9592

9693
You can supply the `--watch` flag to `deno run`, `deno test`, and `deno fmt` to
9794
enable the built-in file watcher. The watcher enables automatic reloading of
@@ -130,106 +127,16 @@ from expanding the glob:
130127
deno run --watch --watch-exclude='*.js' main.ts
131128
```
132129

133-
### Hot Module Replacement mode
134-
135-
You can use `--watch-hmr` flag with `deno run` to enable the hot module
136-
replacement mode. Instead of restarting the program, the runtime will try to
137-
update the program in-place. If updating in-place fails, the program will still
138-
be restarted.
139-
140-
```sh
141-
deno run --watch-hmr main.ts
142-
```
143-
144-
When a hot module replacement is triggered, the runtime will dispatch a
145-
`CustomEvent` of type `hmr` that will include `path` property in its `detail`
146-
object. You can listen for this event and perform any additional logic that you
147-
need to do when a module is updated (eg. notify a browser over a WebSocket
148-
connection).
149-
150-
```ts
151-
addEventListener("hmr", (e) => {
152-
console.log("HMR triggered", e.detail.path);
153-
});
154-
```
155-
156-
### Integrity flags (lock files)
157-
158-
Affect commands which can download resources to the cache: `deno install`,
159-
`deno run`, `deno test`, `deno doc`, and `deno compile`.
160-
161-
```sh
162-
--lock <FILE> Check the specified lock file
163-
--frozen[=<BOOLEAN>] Error out if lockfile is out of date
164-
```
165-
166-
Find out more about these
167-
[here](/runtime/fundamentals/modules/#integrity-checking-and-lock-files).
168-
169-
### Cache and compilation flags
170-
171-
Affect commands which can populate the cache: `deno install`, `deno run`,
172-
`deno test`, `deno doc`, and `deno compile`. As well as the flags above, this
173-
includes those which affect module resolution, compilation configuration etc.
174-
175-
```sh
176-
--config <FILE> Load configuration file
177-
--import-map <FILE> Load import map file
178-
--no-remote Do not resolve remote modules
179-
--reload=<CACHE_BLOCKLIST> Reload source code cache (recompile TypeScript)
180-
```
181-
182-
### Runtime flags
183-
184-
Affect commands which execute user code: `deno run` and `deno test`. These
185-
include all of the above as well as the following.
186-
187-
### Type checking flags
130+
## Where to go next
188131

189-
You can type-check your code (without executing it) using the command:
132+
For deeper coverage of the topics this page only hints at:
190133

191-
```shell
192-
> deno check main.ts
193-
```
194-
195-
You can also type-check your code before execution by using the `--check`
196-
argument to deno run:
197-
198-
```shell
199-
> deno run --check main.ts
200-
```
201-
202-
This flag affects `deno run` and `deno eval`. The following table describes the
203-
type-checking behavior of various subcommands. Here "Local" means that only
204-
errors from local code will induce type-errors, modules imported from https URLs
205-
(remote) may have type errors that are not reported. (To turn on type-checking
206-
for all modules, use `--check=all`.)
207-
208-
| Subcommand | Type checking mode |
209-
| -------------- | ------------------ |
210-
| `deno bench` | 📁 Local |
211-
| `deno check` | 📁 Local |
212-
| `deno compile` | 📁 Local |
213-
| `deno eval` | ❌ None |
214-
| `deno repl` | ❌ None |
215-
| `deno run` | ❌ None |
216-
| `deno test` | 📁 Local |
217-
218-
### Permission flags
219-
220-
These are listed [here](/runtime/fundamentals/security/).
221-
222-
### Other runtime flags
223-
224-
More flags which affect the execution environment.
225-
226-
```sh
227-
--cached-only Require that remote dependencies are already cached
228-
--inspect=<HOST:PORT> activate inspector on host:port ...
229-
--inspect-brk=<HOST:PORT> activate inspector on host:port and break at ...
230-
--inspect-wait=<HOST:PORT> activate inspector on host:port and wait for ...
231-
--location <HREF> Value of 'globalThis.location' used by some web APIs
232-
--prompt Fallback to prompt if required permission wasn't passed
233-
--seed <NUMBER> Seed Math.random()
234-
--v8-flags=<v8-flags> Set V8 command line options. For help: ...
235-
```
134+
- [CLI reference](/runtime/reference/cli/): every subcommand and flag.
135+
- [Security and permissions](/runtime/fundamentals/security/): the `--allow-*`
136+
and `--deny-*` flags in full.
137+
- [Modules and dependencies](/runtime/fundamentals/modules/): lockfiles,
138+
imports, and integrity checking.
139+
- [TypeScript](/runtime/fundamentals/typescript/): when Deno type-checks and how
140+
to control it.
141+
- [Debugging](/runtime/fundamentals/debugging/): the `--inspect` family of flags
142+
and how to attach a debugger.

0 commit comments

Comments
 (0)