Spec-Zone.ru › Deno 2

Run code

Deno runs JavaScript and TypeScript directly (no build step, no config) behind a security sandbox that grants access only when you ask for it. This page covers how your code actually runs: permissions, the ways to launch it, watch mode, and tasks.

Run a file

Point Deno at a file. TypeScript runs as-is:

›_
deno run main.ts

deno run is explicit, but you can drop run for a file or task and Deno will figure it out:

›_
deno main.ts          # same as `deno run main.ts`

Permissions: secure by default

This is the part that's different from Node. Code runs in a sandbox with no access to the network, filesystem, environment, or subprocesses until you grant it. A script that tries to read a file without permission stops and asks, or fails if prompts are disabled.

Grant access with --allow-* flags (each has a short form), and scope them down to exactly what's needed:

›_
deno run --allow-net main.ts                     # network    (-N)
deno run --allow-read=./data main.ts             # filesystem (-R), scoped
deno run -N=api.example.com -E main.ts           # combined, short forms

Use --deny-* to carve out exceptions, or -A / --allow-all to skip the sandbox entirely. That is handy in trusted environments, but it gives up the guarantees. See Permissions for every flag and Security for the model behind them.

Passing script arguments

Arguments for your own script go after the script name; Deno passes them through in Deno.args:

main.ts
console.log(Deno.args);
$ deno run main.ts arg1 arg2 arg3
[ "arg1", "arg2", "arg3" ]

For anything beyond a flat list, parse the arguments with parseArgs from jsr:@std/cli or parseArgs from node:util.

Argument and flag ordering

Caution

Anything passed after the script name is a script argument, not a Deno runtime flag. This is a common source of confusion, so make sure runtime flags appear before the script name.

This leads to the following pitfall:

# Good. We grant net permission to net_client.ts.
deno run --allow-net net_client.ts

# Bad! --allow-net was passed to Deno.args, throws a net permission error.
deno run net_client.ts --allow-net

Run from a URL or stdin

Deno can run code straight from a URL (handy for one-off tools and installers) or from stdin:

›_
deno run https://example.com/script.ts
echo 'console.log(1 + 1)' | deno run -

Remote code is sandboxed like everything else: it gets no permissions unless you grant them.

Reload on change with watch mode

Add --watch and Deno reruns your program whenever a file it depends on changes. No nodemon, no extra dependency:

›_
deno run --watch main.ts

deno test, deno fmt, and others accept --watch too. For what gets watched, excluding paths, and hot module replacement, see Watch mode and HMR.

Run project tasks

Define repeatable commands in deno.json and run them with deno task, the equivalent of npm run:

deno.json
{
  "tasks": {
    "dev": "deno run --watch --allow-net main.ts",
    "start": "deno run --allow-net main.ts"
  }
}
›_
deno task dev

Tasks can run other tasks, set environment variables, and work cross-platform.

Try code quickly

For experiments, evaluate an expression inline or open a REPL:

›_
deno eval "console.log(Deno.version)"
deno repl

Going further

  • Write an HTTP server. Handle requests with the web-standard Deno.serve.
  • Web development. Build apps with Fresh, Next.js, Astro, and web-standard APIs.
  • Web platform APIs. fetch, Request/Response, streams, Web Crypto, and the other browser globals Deno implements.
  • Debugging. Attach Chrome DevTools or your editor's debugger.
  • deno run reference. Every flag in detail.

Last updated on June 15, 2026

© 2018–2025 the Deno authors
Licensed under the MIT License.
https://docs.deno.com/runtime/run

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API