Skip to main content
On this page

deno eval executes a string of code directly from the command line without needing a file. Unlike deno run, deno eval runs with all permissions enabled by default.

Basic usage Jump to heading

›_
deno eval "console.log('Hello from Deno')"

TypeScript works out of the box:

›_
deno eval "const greeting: string = 'Hello'; console.log(greeting)"

CommonJS and ESM auto-detection Jump to heading

Starting in Deno 2.8, deno eval defaults to ESM but switches to CommonJS when the snippet looks like a CJS script. A snippet is treated as CJS only when it has no import / export declarations and it references one of the CommonJS-specific bindings: require(, module.exports, exports., __dirname, or __filename. Anything else — including plain expressions — runs as ESM, matching the longstanding deno eval default.

›_
# Detected as CommonJS — uses require()
deno eval "const path = require('path'); console.log(path.join('a', 'b'))"

# Runs as ESM (the default) — no CJS-specific patterns
deno eval "console.log(1 + 2)"

# Runs as ESM because of the static import
deno eval "import { ok } from 'node:assert'; ok(true); console.log('ok')"

If the heuristic gets it wrong — for example when a snippet mentions require only inside a string — pass --ext=mjs to force ESM or --ext=cjs to force CommonJS.

Printing expression results Jump to heading

Use --print (or -p) to evaluate an expression and print its result, similar to node -p:

›_
deno eval -p "1 + 2"
# 3

deno eval -p "Deno.version"
# { deno: "2.x.x", v8: "...", typescript: "..." }

Reading from stdin Jump to heading

Combine with piped input for quick data processing:

›_
echo '{"name":"deno"}' | deno eval -p "
  const text = await new Response(Deno.stdin.readable).text();
  JSON.parse(text).name
"
Command line usage:
eval

Evaluate a script from the command line

Options Jump to heading

--cached-only
Jump to heading

Require that remote dependencies are already cached.

Load certificate authority from PEM encoded file.

Enable type-checking. This subcommand does not type-check by default; pass --check=all to also type-check remote modules. Alternatively, use the 'deno check' subcommand.

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.

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.

--frozen-lockfile
Jump to heading

Error out if lockfile is out of date.

Load import map file from local file or remote URL.

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
Jump to heading

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

--inspect-publish-uid
Jump to heading
--inspect-wait
Jump to heading

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

Value of globalThis.location used by some web APIs.

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

--min-dep-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).

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

--no-config
Jump to heading

Disable automatic loading of the configuration file.

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
Jump to heading

Selects the node_modules directory mode for npm packages (not a path). One of: auto (create a local node_modules directory and install npm packages into it), manual (use the existing local node_modules directory, do not modify it), none (do not use a local node_modules directory; resolve npm packages from the global cache). Defaults to auto when the flag is passed without a value.

--node-modules-linker
Jump to heading

Sets the linker mode for npm packages (isolated or hoisted).

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

--print, -p
Jump to heading

print result to stdout.

--reload, -r
Jump to heading

Reload source code cache (recompile TypeScript). With no value, reloads everything. Pass a comma-separated list of specifiers to reload only those modules; npm: reloads all npm modules; npm:chalk reloads a single npm module; jsr:@std/http/file-server,jsr:@std/assert/assert-equals reloads specific modules.

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

Set the random number generator seed.

--unsafely-ignore-certificate-errors
Jump to heading

DANGER: Disables verification of TLS certificates.

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.

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

Last updated on

Did you find what you needed?

Edit this page
Privacy policy