Skip to main content
On this page

deno run

用法 Jump to heading

运行本地文件:

>_
deno run main.ts

run 子命令是可选的 — 你也可以直接使用 deno <file>

>_
deno main.ts

默认情况下,Deno 在一个沙箱中运行程序,没有访问磁盘、网络或生成子进程的能力。这是因为 Deno 运行时是 默认安全。你可以使用 `--allow-* 和 --deny-* 标志 来授予或拒绝所需的权限。

权限示例 Jump to heading

授予从磁盘读取和监听网络的权限:

>_
deno run --allow-read --allow-net server.ts

授予从磁盘读取允许列出的文件的权限:

>_
deno run --allow-read=/etc server.ts

授予所有权限 这不推荐,应该仅用于测试

>_
deno run -A server.ts

如果你的项目需要多个安全标志,你应该考虑使用 deno task 来执行它们。

监听文件变化 Jump to heading

要监视文件变化并自动重启进程,使用 --watch 标志。Deno 内置的应用程序监视器会在文件更改时立即重启你的应用程序。

确保在文件名之前放置标志,例如:

>_
deno run --allow-net --watch server.ts

Deno 的监视器会在控制台通知你文件的变化,并在工作时如果出现错误会警告你。

运行 package.json 脚本 Jump to heading

package.json 脚本可以使用 deno task 命令执行。

从 stdin 运行代码 Jump to heading

你可以从 stdin 管道传入代码并立即运行它:

>_
echo "console.log('hello')" | deno run -

终止运行 Jump to heading

要停止运行命令,使用 ctrl + c

Command line usage:
deno run [OPTIONS] [SCRIPT_ARG]...

Run a JavaScript or TypeScript program, or a task or script.

By default all programs are run in sandbox without access to disk, network or ability to spawn subprocesses.

deno run https://docs.deno.com/hello_world.ts

Grant permission to read from disk and listen to network:

deno run --allow-read --allow-net jsr:@std/http/file-server

Grant permission to read allow-listed files from disk:

deno run --allow-read=/etc jsr:@std/http/file-server

Grant all permissions:

deno run -A jsr:@std/http/file-server

Specifying the filename '-' to read the file from stdin.

curl https://docs.deno.com/hello_world.ts | deno run -

Type checking options Jump to heading

--check<CHECK_TYPE>optional
Jump to heading

Enable type-checking. This subcommand does not type-check by default If the value of "all" is supplied, remote modules will be included. Alternatively, the 'deno check' subcommand can be used.

--no-check<NO_CHECK_TYPE>optional
Jump to heading

Skip type-checking. If the value of "remote" is supplied, diagnostic errors from remote modules will be ignored.

Dependency management options Jump to heading

--cached-only
Jump to heading

Require that remote dependencies are already cached.

--frozen<BOOLEAN>optional
Jump to heading

Error out if lockfile is out of date.

Load import map file from local file or remote URL.

--lock<FILE>optional
Jump to heading

Check the specified lock file. (If value is not provided, defaults to "./deno.lock").

Disable auto discovery of the lock file.

Do not resolve npm modules.

--no-remote
Jump to heading

Do not resolve remote modules.

--node-modules-dir<MODE>optional
Jump to heading

Sets the node modules management mode for npm packages.

--reload, -r<CACHE_BLOCKLIST>optional
Jump to heading

Reload source code cache (recompile TypeScript) no value Reload everything jsr:@std/http/file-server,jsr:@std/assert/assert-equals Reloads specific modules npm: Reload all npm modules npm:chalk Reload specific npm module.

--vendor<vendor>optional
Jump to heading

Toggles local vendor folder usage for remote modules and a node_modules folder for npm packages.

Options Jump to heading

--allow-scripts<PACKAGE>optional
Jump to heading

Allow running npm lifecycle scripts for the given packages Note: Scripts will only be executed when using a node_modules directory (--node-modules-dir).

--cert<FILE>
Jump to heading

Load certificate authority from PEM encoded file.

Use this argument to specify custom conditions for npm package exports. You can also use DENO_CONDITIONS env var. .

Configure different aspects of deno including TypeScript, linting, and code formatting. Typically the configuration file will be called deno.json or deno.jsonc and automatically detected; in that case this flag is not necessary.

--coverage<DIR>optional
Jump to heading

Collect coverage profile data into DIR. If DIR is not specified, it uses 'coverage/'. This option can also be set via the DENO_COVERAGE_DIR environment variable.

Start the V8 CPU profiler on startup and write the profile to disk on exit. Profiles are written to the current directory by default.

--cpu-prof-dir<DIR>
Jump to heading

Directory where the V8 CPU profiles will be written. Implicitly enables --cpu-prof.

--cpu-prof-flamegraph
Jump to heading

Generate an SVG flamegraph alongside the CPU profile.

--cpu-prof-interval<MICROSECONDS>
Jump to heading

Sampling interval in microseconds for CPU profiling (default: 1000).

--cpu-prof-md
Jump to heading

Generate a human-readable markdown report alongside the CPU profile.

--cpu-prof-name<NAME>
Jump to heading

Filename for the CPU profile (defaults to CPU...cpuprofile).

--env-file<FILE>optional
Jump to heading

Load environment variables from local file Only the first environment variable with a given key is used. Existing process environment variables are not overwritten, so if variables with the same names already exist in the environment, their values will be preserved. Where multiple declarations for the same environment variable exist in your .env file, the first one encountered is applied. This is determined by the order of the files you pass as arguments.

Set content type of the supplied file.

--location<HREF>
Jump to heading

Value of globalThis.location used by some web APIs.

--minimum-dependency-age<minimum-dependency-age>
Jump to heading

(Unstable) The age in minutes, ISO-8601 duration or RFC3339 absolute timestamp (e.g. '120' for two hours, 'P2D' for two days, '2025-09-16' for cutoff date, '2025-09-16T12:00:00+00:00' for cutoff time, '0' to disable).

--no-code-cache
Jump to heading

Disable V8 code cache feature.

--no-config
Jump to heading

Disable automatic loading of the configuration file.

--preload<FILE>
Jump to heading

A list of files that will be executed before the main module.

--require<FILE>
Jump to heading

A list of CommonJS modules that will be executed before the main module.

--seed<NUMBER>
Jump to heading

Set the random number generator seed.

--tunnel, -t<tunnel>optional
Jump to heading

Execute tasks with a tunnel to Deno Deploy.

Create a secure connection between your local machine and Deno Deploy, providing access to centralised environment variables, logging, and serving from your local environment to the public internet.

--v8-flags<V8_FLAGS>optional
Jump to heading

To see a list of all available flags use --v8-flags=--help Flags can also be set via the DENO_V8_FLAGS environment variable. Any flags set with this flag are appended after the DENO_V8_FLAGS environment variable.

Debugging options Jump to heading

--inspect<HOST_PORT>optional
Jump to heading

Activate inspector on host:port [default: 127.0.0.1:9229]. Host and port are optional. Using port 0 will assign a random free port.

--inspect-brk<HOST_PORT>optional
Jump to heading

Activate inspector on host:port, wait for debugger to connect and break at the start of user script.

--inspect-wait<HOST_PORT>optional
Jump to heading

Activate inspector on host:port and wait for debugger to connect before running user code.

File watching options Jump to heading

--no-clear-screen
Jump to heading

Do not clear terminal screen when under watch mode.

--watch<FILES>optional
Jump to heading

Watch for file changes and restart process automatically. Local files from entry point module graph are watched by default. Additional paths might be watched by passing them as arguments to this flag.

--watch-exclude<FILES>optional
Jump to heading

Exclude provided files/patterns from watch mode.

--watch-hmr<FILES>optional
Jump to heading

Watch for file changes and restart process automatically. Local files from entry point module graph are watched by default. Additional paths might be watched by passing them as arguments to this flag.

Last updated on

你找到了你需要的东西吗?

编辑此页面
隐私政策