On this page
deno eval
deno eval 直接从命令行执行一段代码,无需文件。与 deno run 不同,deno eval 默认在启用所有权限的情况下运行。
基本用法 Jump to heading
deno eval "console.log('来自 Deno 的问候')"
TypeScript 开箱即用:
deno eval "const greeting: string = 'Hello'; console.log(greeting)"
支持 CommonJS Jump to heading
系统会自动识别并支持 CommonJS 模块:
deno eval "const path = require('path'); console.log(path.join('a', 'b'))"
打印表达式结果 Jump to heading
使用 --print(或 -p)来计算表达式并打印其结果,类似于 node -p:
deno eval -p "1 + 2"
# 3
deno eval -p "Deno.version"
# { deno: "2.x.x", v8: "...", typescript: "..." }
从 stdin 读取 Jump to heading
结合管道输入可快速处理数据:
echo '{"name":"deno"}' | deno eval -p "
const text = await new Response(Deno.stdin.readable).text();
JSON.parse(text).name
"
deno eval [OPTIONS] [CODE_ARG]...Evaluate JavaScript from the command line.
deno eval "console.log('hello world')"
To evaluate as TypeScript:
deno eval --ext=ts "const v: string = 'hello'; console.log(v)"
This command has implicit access to all permissions.
Type checking options Jump to heading
--check<CHECK_TYPE>optionalEnable 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>optionalSkip type-checking. If the value of "remote" is supplied, diagnostic errors from remote modules will be ignored.
Dependency management options Jump to heading
--cached-onlyRequire that remote dependencies are already cached.
--frozen<BOOLEAN>optionalError out if lockfile is out of date.
Load import map file from local file or remote URL.
--lock<FILE>optionalCheck the specified lock file. (If value is not provided, defaults to "./deno.lock").
--no-lockDisable auto discovery of the lock file.
--no-npmDo not resolve npm modules.
--no-remoteDo not resolve remote modules.
--node-modules-dir<MODE>optionalSets the node modules management mode for npm packages.
--reload, -r<CACHE_BLOCKLIST>optionalReload 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>optionalToggles local vendor folder usage for remote modules and a node_modules folder for npm packages.
Options Jump to heading
--allow-scripts<PACKAGE>optionalAllow 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>Load certificate authority from PEM encoded file.
--conditions<conditions>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.
--cpu-profStart 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>Directory where the V8 CPU profiles will be written. Implicitly enables --cpu-prof.
--cpu-prof-flamegraphGenerate an SVG flamegraph alongside the CPU profile.
--cpu-prof-interval<MICROSECONDS>Sampling interval in microseconds for CPU profiling (default: 1000).
--cpu-prof-mdGenerate a human-readable markdown report alongside the CPU profile.
--cpu-prof-name<NAME>Filename for the CPU profile (defaults to CPU.
--env-file<FILE>optionalLoad 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.
--ext<ext>Set content type of the supplied file.
--location<HREF>Value of globalThis.location used by some web APIs.
--minimum-dependency-age<minimum-dependency-age>(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-configDisable automatic loading of the configuration file.
--preload<FILE>A list of files that will be executed before the main module.
--print, -pprint result to stdout.
--require<FILE>A list of CommonJS modules that will be executed before the main module.
--seed<NUMBER>Set the random number generator seed.
--v8-flags<V8_FLAGS>optionalTo 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>optionalActivate 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>optionalActivate inspector on host:port, wait for debugger to connect and break at the start of user script.
--inspect-wait<HOST_PORT>optionalActivate inspector on host:port and wait for debugger to connect before running user code.