Runtime
System-related functionality, process management, and observability.
Functions
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.
Returns an object describing the memory usage of the Deno process and the V8 subsystem measured in bytes.
Removes the given signal listener that has been registered with
Deno.addSignalListener.
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.
Interfaces
Type Aliases
Operating signals which can be listened for or sent to sub-processes. What signals and what their standard behaviors are OS dependent.
Variables
Information related to the build of the current Deno runtime.
The URL of the entrypoint module entered from the command-line. It requires read permission to the CWD.
Version information related to the current Deno CLI runtime environment.
function Deno.addSignalListener
#addSignalListener(signal: Signal,handler: () => void,): voidfunction Deno.chdir
#chdir(directory: string | URL): voidChange 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(): stringReturn 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
function Deno.hostname
function Deno.loadavg
#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(): MemoryUsageReturns an object describing the memory usage of the Deno process and the V8 subsystem measured in bytes.
Return Type #
function Deno.osRelease
function Deno.osUptime
function Deno.refTimer
function Deno.removeSignalListener
#removeSignalListener(signal: Signal,handler: () => void,): voidRemoves 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 #
Return Type #
void function Deno.systemMemoryInfo
#systemMemoryInfo(): SystemMemoryInfoDisplays 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 #
function Deno.unrefTimer
interface Deno.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 #
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 the value of an environment variable.
Deno.env.set("SOME_VAR", "Value");
Deno.env.get("SOME_VAR"); // outputs "Value"
Requires allow-env permission.
Delete the value of an environment variable.
Deno.env.set("SOME_VAR", "Value");
Deno.env.delete("SOME_VAR"); // outputs "undefined"
Requires allow-env permission.
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.
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 #
The number of bytes of the current Deno's process resident set size, which is the amount of memory occupied in main memory (RAM).
interface Deno.SystemMemoryInfo
Information returned from a call to Deno.systemMemoryInfo.
Properties #
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.
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 #
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.
#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 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
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.
Type #
boolean 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 #
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.