The deno run command executes JavaScript or TypeScript programs with the Deno runtime.
Usage
deno run [OPTIONS] <SCRIPT> [SCRIPT_ARGS]...
Basic Examples
# Run a local file
deno run main.ts
# Run a remote file
deno run https://deno.land/std/examples/welcome.ts
# Run with permissions
deno run --allow-net --allow-read server.ts
# Run with arguments
deno run main.ts --port 8000
# Run from stdin
cat script.ts | deno run -
Permission Flags
Allow all permissions (equivalent to enabling all permission flags)
Allow environment access# Allow all environment variables
deno run --allow-env script.ts
# Allow specific variables
deno run --allow-env=HOME,USER script.ts
Allow file system read access# Allow reading all files
deno run --allow-read script.ts
# Allow reading specific directories
deno run --allow-read=/tmp,/var/log script.ts
Allow file system write access# Allow writing all files
deno run --allow-write script.ts
# Allow writing to specific directory
deno run --allow-write=./output script.ts
Allow network access# Allow all network access
deno run --allow-net script.ts
# Allow specific domains
deno run --allow-net=deno.land,github.com script.ts
Allow running subprocesses# Allow running any subprocess
deno run --allow-run script.ts
# Allow running specific programs
deno run --allow-run=git,npm script.ts
Allow access to system information# Allow all system APIs
deno run --allow-sys script.ts
# Allow specific system APIs
deno run --allow-sys=osRelease,hostname script.ts
Allow loading dynamic libraries (Foreign Function Interface)deno run --allow-ffi script.ts
deno run --allow-ffi=./lib.so script.ts
Deny Flags
Each permission has a corresponding deny flag:
Deny file system read access
Deny file system write access
Deny running subprocesses
Deny system information access
Runtime Options
Disable permission prompts (automatically deny any required permissions)
Require that remote dependencies are already cached
Set a custom location for the scriptdeno run --location https://example.com script.ts
Set the seed for the random number generatordeno run --seed=42 script.ts
Set V8 command line optionsdeno run --v8-flags=--max-old-space-size=8192 script.ts
Watch Mode
Watch for file changes and restart automatically# Watch the script and its dependencies
deno run --watch main.ts
# Watch specific paths
deno run --watch=src/,config/ main.ts
# Watch with exclude patterns
deno run --watch --watch-exclude=test/ main.ts
Watch for file changes and reload using Hot Module Replacementdeno run --watch-hmr main.ts
Don’t clear the screen when watch mode restarts
Type Checking
Enable type checking (optionally specify which modules to check)# Type-check all modules
deno run --check main.ts
# Type-check only local modules
deno run --check=local main.ts
Skip type checking (default for deno run)
Module Resolution
Load import map filedeno run --import-map=import_map.json main.ts
Create a node_modules directory for npm packagesdeno run --node-modules-dir main.ts
Enable vendoring of remote modules
Coverage
Collect coverage profile data into the specified directorydeno run --coverage=cov_profile main.ts
Configuration
Load configuration from a filedeno run --config=deno.json main.ts
Disable automatic configuration file detection
Lock File
Check the specified lock filedeno run --lock=deno.lock main.ts
Error if lock file is out of date
Environment
Load environment variables from a filedeno run --env=.env main.ts
deno run --env=.env.local,.env main.ts
Inspector
Activate inspector on host:port (default: 127.0.0.1:9229)deno run --inspect main.ts
deno run --inspect=0.0.0.0:9229 main.ts
Activate inspector and break at start of user script
Activate inspector and wait for debugger to connect before running user code
Examples
Basic Server
// server.ts
Deno.serve(() => new Response("Hello, World!"));
deno run --allow-net server.ts
File Operations
// file-ops.ts
const text = await Deno.readTextFile("./data.txt");
await Deno.writeTextFile("./output.txt", text.toUpperCase());
deno run --allow-read=./data.txt --allow-write=./output.txt file-ops.ts
Subprocess Execution
// git-info.ts
const command = new Deno.Command("git", {
args: ["log", "-1"],
});
const { stdout } = await command.output();
console.log(new TextDecoder().decode(stdout));
deno run --allow-run=git git-info.ts