Spec-Zone.ru › Deno 2

Runtime

System-related functionality, process management, and observability.

Eg Deno.mainModule, Deno.exit, Deno.cwd


function Deno.addSignalListener

addSignalListener(
signal: Signal,
handler: () => void,
): void

Registers the given function as a listener of the given signal event.

Deno.addSignalListener(
  "SIGTERM",
  () => {
    console.log("SIGTERM!")
  }
);

Note: On Windows only "SIGINT" (CTRL+C), "SIGBREAK" (CTRL+Break), "SIGTERM", "SIGQUIT", "SIGHUP", and "SIGWINCH" are supported.

Parameters

signal: Signal
handler: () => void

Return Type

void

function Deno.chdir

allow-read
chdir(directory: string | URL): void

Change the current working directory to the specified path.

Deno.chdir("/home/userA");
Deno.chdir("../userB");
Deno.chdir("C:\\Program Files (x86)\\Java");

Throws Deno.errors.NotFound if directory not found.

Throws Deno.errors.PermissionDenied if the user does not have operating system file access rights.

Requires allow-read permission.

Parameters

directory: string | URL

Return Type

void

function Deno.cwd

cwd(): string

Return a string representing the current working directory.

If the current directory can be reached via multiple paths (due to symbolic links), cwd() may return any one of them.

const currentWorkingDirectory = Deno.cwd();

Throws Deno.errors.NotFound if directory not available.

Return Type

string

function Deno.execPath

execPath(): string

Returns the path to the current deno executable.

console.log(Deno.execPath());  // e.g. "/home/alice/.local/bin/deno"

Return Type

string

function Deno.exit

exit(code?: number): never

Exit the Deno process with optional exit code.

If no exit code is supplied then Deno will exit with return code of 0.

In worker contexts this closes the current worker using Deno's internal worker close operation. It does not call the current self.close property.

Deno.exit(5);

Parameters

code: number
optional

Return Type

never

function Deno.gid

allow-sys
gid(): number | null

Returns the group id of the process on POSIX platforms. Returns null on windows.

console.log(Deno.gid());

Requires allow-sys permission.

Return Type

number | null

function Deno.hostname

allow-sys
hostname(): string

Get the hostname of the machine the Deno process is running on.

console.log(Deno.hostname());

Requires allow-sys permission.

Return Type

string

function Deno.loadavg

allow-sys
loadavg(): number[]

Returns an array containing the 1, 5, and 15 minute load averages. The load average is a measure of CPU and IO utilization of the last one, five, and 15 minute periods expressed as a fractional number. Zero means there is no load. On Windows, the three values are always the same and represent the current load, not the 1, 5 and 15 minute load averages.

console.log(Deno.loadavg());  // e.g. [ 0.71, 0.44, 0.44 ]

Requires allow-sys permission.

On Windows there is no API available to retrieve this information and this method returns [ 0, 0, 0 ].

Return Type

number[]

function Deno.memoryUsage

memoryUsage(): MemoryUsage

Returns an object describing the memory usage of the Deno process and the V8 subsystem measured in bytes.

Return Type

MemoryUsage

function Deno.osRelease

allow-sys
osRelease(): string

Returns the release version of the Operating System.

console.log(Deno.osRelease());

Requires allow-sys permission. Under consideration to possibly move to Deno.build or Deno.versions and if it should depend sys-info, which may not be desirable.

Return Type

string

function Deno.osUptime

allow-sys
osUptime(): number

Returns the Operating System uptime in number of seconds.

console.log(Deno.osUptime());

Requires allow-sys permission.

Return Type

number

function Deno.refTimer

refTimer(id: number | NodeJS.Timeout): void

Make the timer of the given id block the event loop from finishing.

Parameters

id: number | NodeJS.Timeout

Return Type

void

function Deno.removeSignalListener

removeSignalListener(
signal: Signal,
handler: () => void,
): void

Removes the given signal listener that has been registered with Deno.addSignalListener.

const listener = () => {
  console.log("SIGTERM!")
};
Deno.addSignalListener("SIGTERM", listener);
Deno.removeSignalListener("SIGTERM", listener);

Note: On Windows only "SIGINT" (CTRL+C), "SIGBREAK" (CTRL+Break), "SIGTERM", "SIGQUIT", "SIGHUP", and "SIGWINCH" are supported.

Parameters

signal: Signal
handler: () => void

Return Type

void

function Deno.systemMemoryInfo

allow-sys
systemMemoryInfo(): SystemMemoryInfo

Displays the total amount of free and used physical and swap memory in the system, as well as the buffers and caches used by the kernel.

This is similar to the free command in Linux

console.log(Deno.systemMemoryInfo());

Requires allow-sys permission.

Return Type

SystemMemoryInfo

function Deno.uid

allow-sys
uid(): number | null

Returns the user id of the process on POSIX platforms. Returns null on Windows.

console.log(Deno.uid());

Requires allow-sys permission.

Return Type

number | null

function Deno.unrefTimer

unrefTimer(id: number | NodeJS.Timeout): void

Make the timer of the given id not block the event loop from finishing.

Parameters

id: number | NodeJS.Timeout

Return Type

void

interface Deno.Env

allow-env

An interface containing methods to interact with the process environment variables.

Environment variables can also be loaded from a .env file by using the --env-file flag when running a Deno program:

deno run --env-file=.env --allow-env main.ts

If --env-file is specified without a value, it defaults to loading .env from the current working directory:

deno run --env-file --allow-env main.ts

Learn more at the Deno docs.

Methods

get(key: string): string | undefined

Retrieve the value of an environment variable.

Returns undefined if the supplied environment variable is not defined.

console.log(Deno.env.get("HOME"));  // e.g. outputs "/home/alice"
console.log(Deno.env.get("MADE_UP_VAR"));  // outputs undefined

Requires allow-env permission.

set(
key: string,
value: string,
): void

Set the value of an environment variable.

Deno.env.set("SOME_VAR", "Value");
Deno.env.get("SOME_VAR");  // outputs "Value"

Requires allow-env permission.

delete(key: string): void

Delete the value of an environment variable.

Deno.env.set("SOME_VAR", "Value");
Deno.env.delete("SOME_VAR");  // outputs "undefined"

Requires allow-env permission.

has(key: string): boolean

Check whether an environment variable is present or not.

Deno.env.set("SOME_VAR", "Value");
Deno.env.has("SOME_VAR");  // outputs true

Requires allow-env permission.

toObject(): { [index: string]: string; }

Returns a snapshot of the environment variables at invocation as a simple object of keys and values.

Deno.env.set("TEST_VAR", "A");
const myEnv = Deno.env.toObject();
console.log(myEnv.SHELL);
Deno.env.set("TEST_VAR", "B");
console.log(myEnv.TEST_VAR);  // outputs "A"

Requires allow-env permission.


interface Deno.MemoryUsage

Properties

rss: number

The number of bytes of the current Deno's process resident set size, which is the amount of memory occupied in main memory (RAM).

heapTotal: number

The total size of the heap for V8, in bytes.

heapUsed: number

The amount of the heap used for V8, in bytes.

external: number

Memory, in bytes, associated with JavaScript objects outside of the JavaScript isolate.


interface Deno.SystemMemoryInfo

Information returned from a call to Deno.systemMemoryInfo.

Properties

total: number

Total installed memory in bytes.

free: number

Unused memory in bytes.

available: number

Estimation of how much memory, in bytes, is available for starting new applications, without swapping. Unlike the data provided by the cache or free fields, this field takes into account page cache and also that not all reclaimable memory will be reclaimed due to items being in use.

buffers: number

Memory used by kernel buffers.

cached: number

Memory used by the page cache and slabs.

swapTotal: number

Total swap memory.

swapFree: number

Unused swap memory.


type alias Deno.Signal

Operating signals which can be listened for or sent to sub-processes. What signals and what their standard behaviors are OS dependent.

Definition

"SIGABRT"
| "SIGALRM"
| "SIGBREAK"
| "SIGBUS"
| "SIGCHLD"
| "SIGCONT"
| "SIGEMT"
| "SIGFPE"
| "SIGHUP"
| "SIGILL"
| "SIGINFO"
| "SIGINT"
| "SIGIO"
| "SIGPOLL"
| "SIGUNUSED"
| "SIGKILL"
| "SIGPIPE"
| "SIGPROF"
| "SIGPWR"
| "SIGQUIT"
| "SIGSEGV"
| "SIGSTKFLT"
| "SIGSTOP"
| "SIGSYS"
| "SIGTERM"
| "SIGTRAP"
| "SIGTSTP"
| "SIGTTIN"
| "SIGTTOU"
| "SIGURG"
| "SIGUSR1"
| "SIGUSR2"
| "SIGVTALRM"
| "SIGWINCH"
| "SIGXCPU"
| "SIGXFSZ"

variable Deno.args

Returns the script arguments to the program.

Give the following command line invocation of Deno:

deno eval "console.log(Deno.args)" Sushi Maguro Hamachi

Then Deno.args will contain:

[ "Sushi", "Maguro", "Hamachi" ]

If you are looking for a structured way to parse arguments, there is parseArgs() from the Deno Standard Library.

Type

string[]

variable Deno.build

Information related to the build of the current Deno runtime.

Users are discouraged from code branching based on this information, as assumptions about what is available in what build environment might change over time. Developers should specifically sniff out the features they intend to use.

The intended use for the information is for logging and debugging purposes.

Properties

target: string

The LLVM target triple, which is the combination of ${arch}-${vendor}-${os} and represent the specific build target that the current runtime was built for.

arch: "x86_64" | "aarch64"

Instruction set architecture that the Deno CLI was built for.

os:
"darwin"
| "linux"
| "android"
| "windows"
| "freebsd"
| "netbsd"
| "aix"
| "solaris"
| "illumos"

The operating system that the Deno CLI was built for. "darwin" is also known as OSX or MacOS.

standalone: boolean
vendor: string

The computer vendor that the Deno CLI was built for.

env: string
optional

Optional environment flags that were set for this build of Deno CLI.


variable Deno.env

allow-env

An interface containing methods to interact with the process environment variables.

Type

Env

variable Deno.exitCode

The exit code for the Deno process.

If no exit code has been supplied, then Deno will assume a return code of 0.

When setting an exit code value, a number or non-NaN string must be provided, otherwise a TypeError will be thrown.

console.log(Deno.exitCode); //-> 0
Deno.exitCode = 1;
console.log(Deno.exitCode); //-> 1

Type

number

variable Deno.mainModule

allow-read

The URL of the entrypoint module entered from the command-line. It requires read permission to the CWD.

Also see ImportMeta for other related information.

Type

string

variable Deno.noColor

Reflects the NO_COLOR environment variable at program start.

When the value is true, the Deno CLI will attempt to not send color codes to stderr or stdout and other command line programs should also attempt to respect this value.

See: https://no-color.org/

Type

boolean

variable Deno.pid

The current process ID of this instance of the Deno CLI.

console.log(Deno.pid);

Type

number

variable Deno.ppid

The process ID of parent process of this instance of the Deno CLI.

console.log(Deno.ppid);

Type

number

variable Deno.version

Version information related to the current Deno CLI runtime environment.

Users are discouraged from code branching based on this information, as assumptions about what is available in what build environment might change over time. Developers should specifically sniff out the features they intend to use.

The intended use for the information is for logging and debugging purposes.

Properties

deno: string

Deno CLI's version. For example: "1.26.0".

v8: string

The V8 version used by Deno. For example: "10.7.100.0".

V8 is the underlying JavaScript runtime platform that Deno is built on top of.

typescript: string

The TypeScript version used by Deno. For example: "4.8.3".

A version of the TypeScript type checker and language server is built-in to the Deno CLI.


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

Spec-Zone.ru

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