Options
All
  • Public
  • Public/Protected
  • All
Menu

Index

Type aliases

Arch

Arch: "x64" | "arm64"

ConsoleOptions

ConsoleOptions: Partial<object>

Network

Network: "tcp"

OpenMode

OpenMode: "r" | "r+" | "w" | "w+" | "a" | "a+" | "x" | "x+"

OperatingSystem

OperatingSystem: "mac" | "win" | "linux"

Permission

Permission: keyof Permissions

ProcessStdio

ProcessStdio: "inherit" | "piped" | "null"

How to handle subprocess stdio.

"inherit" The default if unspecified. The child inherits from the corresponding parent descriptor.

"piped" A new pipe should be arranged to connect the parent and child subprocesses.

"null" This stream will be ignored. This is the equivalent of attaching the stream to /dev/null.

Variables

Const EOF

EOF: null

Const Signal

Signals numbers. This is platform dependent.

Const args

args: string[]

Const build

build: BuildInfo

Const customInspect

customInspect: keyof symbol

A symbol which can be used as a key for a custom method which will be called when Deno.inspect() is called, or when the object is logged to the console.

Let noColor

noColor: boolean

Reflects the NO_COLOR environment variable: https://no-color.org/

Let pid

pid: number

The current process id of the runtime.

Const stderr

stderr: File

An instance of File for stderr.

Const stdin

stdin: File

An instance of File for stdin.

Const stdout

stdout: File

An instance of File for stdout.

Const version

version: Version

Functions

applySourceMap

  • Given a current location in a module, lookup the source location and return it.

    When Deno transpiles code, it keep source maps of the transpiled code. This function can be used to lookup the original location. This is automatically done when accessing the .stack of an error, or when an uncaught error is logged. This function can be used to perform the lookup for creating better error handling.

    Note: line and column are 1 indexed, which matches display expectations, but is not typical of most index numbers in Deno.

    An example:

      const orig = Deno.applySourceMap({
        location: "file://my/module.ts",
        line: 5,
        column: 15
      });
      console.log(`${orig.filename}:${orig.line}:${orig.column}`);

    Parameters

    Returns Location

chdir

  • chdir(directory: string): void
  • chdir() Change the current working directory to path. throws NotFound exception if directory not available

    Parameters

    • directory: string

    Returns void

chmod

  • chmod(path: string, mode: number): Promise<void>
  • Changes the permission of a specific file/directory of specified path.

      await Deno.chmod("/path/to/file", 0o666);

    Parameters

    • path: string
    • mode: number

    Returns Promise<void>

chmodSync

  • chmodSync(path: string, mode: number): void
  • Changes the permission of a specific file/directory of specified path synchronously.

      Deno.chmodSync("/path/to/file", 0o666);

    Parameters

    • path: string
    • mode: number

    Returns void

chown

  • chown(path: string, uid: number, gid: number): Promise<void>
  • Change owner of a regular file or directory asynchronously. Unix only at the moment.

    Parameters

    • path: string

      path to the file

    • uid: number

      user id of the new owner

    • gid: number

      group id of the new owner

    Returns Promise<void>

chownSync

  • chownSync(path: string, uid: number, gid: number): void
  • Change owner of a regular file or directory synchronously. Unix only at the moment.

    Parameters

    • path: string

      path to the file

    • uid: number

      user id of the new owner

    • gid: number

      group id of the new owner

    Returns void

close

  • close(rid: number): void

connect

  • connect(_network: Network, _address: string): Promise<Conn>

copy

  • Copies from src to dst until either EOF is reached on src or an error occurs. It returns the number of bytes copied and the first error encountered while copying, if any.

    Because copy() is defined to read from src until EOF, it does not treat an EOF from read() as an error to be reported.

    Parameters

    Returns Promise<number>

copyFile

  • copyFile(from: string, to: string): Promise<void>
  • Copies the contents of a file to another by name.

    Creates a new file if target does not exists, and if target exists, overwrites original content of the target file.

    It would also copy the permission of the original file to the destination.

      await Deno.copyFile("from.txt", "to.txt");

    Parameters

    • from: string
    • to: string

    Returns Promise<void>

copyFileSync

  • copyFileSync(from: string, to: string): void
  • Copies the contents of a file to another by name synchronously. Creates a new file if target does not exists, and if target exists, overwrites original content of the target file.

    It would also copy the permission of the original file to the destination.

      Deno.copyFileSync("from.txt", "to.txt");

    Parameters

    • from: string
    • to: string

    Returns void

cwd

  • cwd(): string
  • cwd() 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. throws NotFound exception if directory not available

    Returns string

dial

  • dial(network: Network, address: string): Promise<Conn>
  • Dial connects to the address on the named network.

    Supported networks are only tcp currently.

    TODO: tcp4 (IPv4-only), tcp6 (IPv6-only), udp, udp4 (IPv4-only), udp6 (IPv6-only), ip, ip4 (IPv4-only), ip6 (IPv6-only), unix, unixgram and unixpacket.

    For TCP and UDP networks, the address has the form host:port. The host must be a literal IP address, or a host name that can be resolved to IP addresses. The port must be a literal port number or a service name. If the host is a literal IPv6 address it must be enclosed in square brackets, as in [2001:db8::1]:80 or [fe80::1%zone]:80. The zone specifies the scope of the literal IPv6 address as defined in RFC 4007. The functions JoinHostPort and SplitHostPort manipulate a pair of host and port in this form. When using TCP, and the host resolves to multiple IP addresses, Dial will try each IP address in order until one succeeds.

    Examples:

    dial("tcp", "golang.org:http")
    dial("tcp", "192.0.2.1:http")
    dial("tcp", "198.51.100.1:80")
    dial("udp", "[2001:db8::1]:domain")
    dial("udp", "[fe80::1%lo0]:53")
    dial("tcp", ":80")

    Parameters

    Returns Promise<Conn>

env

  • env(): object
  • Returns a snapshot of the environment variables at invocation. Mutating a property in the object will set that variable in the environment for the process. The environment object will only accept strings as values.

      const myEnv = Deno.env();
      console.log(myEnv.SHELL);
      myEnv.TEST_VAR = "HELLO";
      const newEnv = Deno.env();
      console.log(myEnv.TEST_VAR == newEnv.TEST_VAR);

    Returns object

    • [index: string]: string

execPath

  • execPath(): string
  • Returns the path to the current deno executable. Requires the --allow-env flag.

    Returns string

exit

  • exit(code?: number): never
  • Exit the Deno process with optional exit code.

    Parameters

    • Optional code: number

    Returns never

homeDir

  • homeDir(): string
  • Returns the current user's home directory. Requires the --allow-env flag.

    Returns string

inspect

  • inspect() converts input into string that has the same format as printed by console.log(...);

    Parameters

    Returns string

isTTY

  • isTTY(): object
  • Check if running in terminal.

      console.log(Deno.isTTY().stdout);

    Returns object

    • stderr: boolean
    • stdin: boolean
    • stdout: boolean

kill

  • kill(pid: number, signo: number): void
  • Send a signal to process under given PID. Unix only at this moment. If pid is negative, the signal will be sent to the process group identified by -pid. Requires the --allow-run flag.

    Parameters

    • pid: number
    • signo: number

    Returns void

link

  • link(oldname: string, newname: string): Promise<void>
  • Creates newname as a hard link to oldname.

      await Deno.link("old/name", "new/name");

    Parameters

    • oldname: string
    • newname: string

    Returns Promise<void>

linkSync

  • linkSync(oldname: string, newname: string): void
  • Synchronously creates newname as a hard link to oldname.

      Deno.linkSync("old/name", "new/name");

    Parameters

    • oldname: string
    • newname: string

    Returns void

listen

  • Listen announces on the local network address.

    The network must be tcp, tcp4, tcp6, unix or unixpacket.

    For TCP networks, if the host in the address parameter is empty or a literal unspecified IP address, listen() listens on all available unicast and anycast IP addresses of the local system. To only use IPv4, use network tcp4. The address can use a host name, but this is not recommended, because it will create a listener for at most one of the host's IP addresses. If the port in the address parameter is empty or 0, as in 127.0.0.1: or [::1]:0, a port number is automatically chosen. The addr() method of Listener can be used to discover the chosen port.

    See dial() for a description of the network and address parameters.

    Parameters

    Returns Listener

lstat

  • lstat(filename: string): Promise<FileInfo>
  • Queries the file system for information on the path provided. If the given path is a symlink information about the symlink will be returned.

      const fileInfo = await Deno.lstat("hello.txt");
      assert(fileInfo.isFile());

    Parameters

    • filename: string

    Returns Promise<FileInfo>

lstatSync

  • Queries the file system for information on the path provided synchronously. If the given path is a symlink information about the symlink will be returned.

      const fileInfo = Deno.lstatSync("hello.txt");
      assert(fileInfo.isFile());

    Parameters

    • filename: string

    Returns FileInfo

makeTempDir

  • makeTempDir creates a new temporary directory in the directory dir, its name beginning with prefix and ending with suffix. It returns the full path to the newly created directory. If dir is unspecified, tempDir uses the default directory for temporary files. Multiple programs calling tempDir simultaneously will not choose the same directory. It is the caller's responsibility to remove the directory when no longer needed.

      const tempDirName0 = await Deno.makeTempDir();
      const tempDirName1 = await Deno.makeTempDir({ prefix: 'my_temp' });

    Parameters

    Returns Promise<string>

makeTempDirSync

  • makeTempDirSync is the synchronous version of makeTempDir.

      const tempDirName0 = Deno.makeTempDirSync();
      const tempDirName1 = Deno.makeTempDirSync({ prefix: 'my_temp' });

    Parameters

    Returns string

metrics

  • Receive metrics from the privileged side of Deno.

     > console.table(Deno.metrics())
     ┌──────────────────┬────────┐
     │     (index)      │ Values │
     ├──────────────────┼────────┤
     │  opsDispatched   │   9    │
     │   opsCompleted   │   9    │
     │ bytesSentControl │  504   │
     │  bytesSentData   │   0    │
     │  bytesReceived   │  856   │
     └──────────────────┴────────┘

    Returns Metrics

mkdir

  • mkdir(path: string, recursive?: boolean, mode?: number): Promise<void>
  • Creates a new directory with the specified path. If recursive is set to true, nested directories will be created (also known as "mkdir -p"). mode sets permission bits (before umask) on UNIX and does nothing on Windows.

      await Deno.mkdir("new_dir");
      await Deno.mkdir("nested/directories", true);

    Parameters

    • path: string
    • Optional recursive: boolean
    • Optional mode: number

    Returns Promise<void>

mkdirSync

  • mkdirSync(path: string, recursive?: boolean, mode?: number): void
  • Creates a new directory with the specified path synchronously. If recursive is set to true, nested directories will be created (also known as "mkdir -p"). mode sets permission bits (before umask) on UNIX and does nothing on Windows.

      Deno.mkdirSync("new_dir");
      Deno.mkdirSync("nested/directories", true);

    Parameters

    • path: string
    • Optional recursive: boolean
    • Optional mode: number

    Returns void

open

  • Open a file and return an instance of the File object.

      (async () => {
        const file = await Deno.open("/foo/bar.txt");
      })();

    Parameters

    • filename: string
    • Optional mode: OpenMode

    Returns Promise<File>

openSync

  • Open a file and return an instance of the File object synchronously.

      const file = Deno.openSync("/foo/bar.txt");

    Parameters

    • filename: string
    • Optional mode: OpenMode

    Returns File

permissions

  • Inspect granted permissions for the current program.

      if (Deno.permissions().read) {
        const file = await Deno.readFile("example.test");
        // ...
      }

    Returns Permissions

read

  • read(rid: number, p: Uint8Array): Promise<number | EOF>
  • Read from a file ID into an array buffer.

    Resolves with the number | EOF for the operation.

      (async () => {
        const file = await Deno.open("/foo/bar.txt");
        const buf = new Uint8Array(100);
        const nread = await Deno.read(file.rid, buf);
        const text = new TextDecoder().decode(buf);
      })();

    Parameters

    • rid: number
    • p: Uint8Array

    Returns Promise<number | EOF>

readAll

  • readAll(r: Reader): Promise<Uint8Array>

readAllSync

readDir

  • readDir(path: string): Promise<FileInfo[]>
  • Reads the directory given by path and returns a list of file info.

      const files = await Deno.readDir("/");

    Parameters

    • path: string

    Returns Promise<FileInfo[]>

readDirSync

  • Reads the directory given by path and returns a list of file info synchronously.

      const files = Deno.readDirSync("/");

    Parameters

    • path: string

    Returns FileInfo[]

readFile

  • readFile(filename: string): Promise<Uint8Array>
  • Read the entire contents of a file.

      const decoder = new TextDecoder("utf-8");
      const data = await Deno.readFile("hello.txt");
      console.log(decoder.decode(data));

    Parameters

    • filename: string

    Returns Promise<Uint8Array>

readFileSync

  • readFileSync(filename: string): Uint8Array
  • Read the entire contents of a file synchronously.

      const decoder = new TextDecoder("utf-8");
      const data = Deno.readFileSync("hello.txt");
      console.log(decoder.decode(data));

    Parameters

    • filename: string

    Returns Uint8Array

readSync

  • readSync(rid: number, p: Uint8Array): number | EOF
  • Read synchronously from a file ID into an array buffer.

    Return number | EOF for the operation.

     const file = Deno.openSync("/foo/bar.txt");
     const buf = new Uint8Array(100);
     const nread = Deno.readSync(file.rid, buf);
     const text = new TextDecoder().decode(buf);

    Parameters

    • rid: number
    • p: Uint8Array

    Returns number | EOF

readlink

  • readlink(name: string): Promise<string>
  • Returns the destination of the named symbolic link.

      const targetPath = await Deno.readlink("symlink/path");

    Parameters

    • name: string

    Returns Promise<string>

readlinkSync

  • readlinkSync(name: string): string
  • Returns the destination of the named symbolic link synchronously.

      const targetPath = Deno.readlinkSync("symlink/path");

    Parameters

    • name: string

    Returns string

remove

  • remove(path: string, options?: RemoveOption): Promise<void>
  • Removes the named file or directory. Would throw error if permission denied, not found, or directory not empty if recursive set to false. recursive is set to false by default.

      await Deno.remove("/path/to/dir/or/file", {recursive: false});

    Parameters

    Returns Promise<void>

removeSync

  • Removes the named file or directory synchronously. Would throw error if permission denied, not found, or directory not empty if recursive set to false. recursive is set to false by default.

      Deno.removeSync("/path/to/dir/or/file", {recursive: false});

    Parameters

    Returns void

rename

  • rename(oldpath: string, newpath: string): Promise<void>
  • Renames (moves) oldpath to newpath. If newpath already exists and is not a directory, rename() replaces it. OS-specific restrictions may apply when oldpath and newpath are in different directories.

      await Deno.rename("old/path", "new/path");

    Parameters

    • oldpath: string
    • newpath: string

    Returns Promise<void>

renameSync

  • renameSync(oldpath: string, newpath: string): void
  • Synchronously renames (moves) oldpath to newpath. If newpath already exists and is not a directory, renameSync() replaces it. OS-specific restrictions may apply when oldpath and newpath are in different directories.

      Deno.renameSync("old/path", "new/path");

    Parameters

    • oldpath: string
    • newpath: string

    Returns void

resources

revokePermission

  • Revoke a permission. When the permission was already revoked nothing changes

      if (Deno.permissions().read) {
        const file = await Deno.readFile("example.test");
        Deno.revokePermission('read');
      }
      Deno.readFile("example.test"); // -> error or permission prompt

    Parameters

    Returns void

run

  • Spawns new subprocess.

    Subprocess uses same working directory as parent process unless opt.cwd is specified.

    Environmental variables for subprocess can be specified using opt.env mapping.

    By default subprocess inherits stdio of parent process. To change that opt.stdout, opt.stderr and opt.stdin can be specified independently - they can be set to either ProcessStdio or rid of open file.

    Parameters

    Returns Process

seek

  • seek(rid: number, offset: number, whence: SeekMode): Promise<void>
  • Seek a file ID to the given offset under mode given by whence.

     (async () => {
       const file = await Deno.open("/foo/bar.txt");
       await Deno.seek(file.rid, 0, 0);
     })();

    Parameters

    • rid: number
    • offset: number
    • whence: SeekMode

    Returns Promise<void>

seekSync

  • seekSync(rid: number, offset: number, whence: SeekMode): void
  • Seek a file ID synchronously to the given offset under mode given by whence.

      const file = Deno.openSync("/foo/bar.txt");
      Deno.seekSync(file.rid, 0, 0);

    Parameters

    • rid: number
    • offset: number
    • whence: SeekMode

    Returns void

stat

  • stat(filename: string): Promise<FileInfo>
  • Queries the file system for information on the path provided. stat Will always follow symlinks.

      const fileInfo = await Deno.stat("hello.txt");
      assert(fileInfo.isFile());

    Parameters

    • filename: string

    Returns Promise<FileInfo>

statSync

  • Queries the file system for information on the path provided synchronously. statSync Will always follow symlinks.

      const fileInfo = Deno.statSync("hello.txt");
      assert(fileInfo.isFile());

    Parameters

    • filename: string

    Returns FileInfo

symlink

  • symlink(oldname: string, newname: string, type?: string): Promise<void>
  • Creates newname as a symbolic link to oldname. The type argument can be set to dir or file and is only available on Windows (ignored on other platforms).

      await Deno.symlink("old/name", "new/name");

    Parameters

    • oldname: string
    • newname: string
    • Optional type: string

    Returns Promise<void>

symlinkSync

  • symlinkSync(oldname: string, newname: string, type?: string): void
  • Synchronously creates newname as a symbolic link to oldname. The type argument can be set to dir or file and is only available on Windows (ignored on other platforms).

      Deno.symlinkSync("old/name", "new/name");

    Parameters

    • oldname: string
    • newname: string
    • Optional type: string

    Returns void

toAsyncIterator

  • toAsyncIterator(r: Reader): AsyncIterableIterator<Uint8Array>
  • Turns r into async iterator.

     for await (const chunk of toAsyncIterator(reader)) {
         console.log(chunk)
     }

    Parameters

    Returns AsyncIterableIterator<Uint8Array>

truncate

  • truncate(name: string, len?: number): Promise<void>
  • Truncates or extends the specified file, updating the size of this file to become size.

      await Deno.truncate("hello.txt", 10);

    Parameters

    • name: string
    • Optional len: number

    Returns Promise<void>

truncateSync

  • truncateSync(name: string, len?: number): void
  • Truncates or extends the specified file synchronously, updating the size of this file to become size.

      Deno.truncateSync("hello.txt", 10);

    Parameters

    • name: string
    • Optional len: number

    Returns void

utime

  • utime(filename: string, atime: number | Date, mtime: number | Date): Promise<void>
  • Changes the access and modification times of a file system object referenced by filename. Given times are either in seconds (Unix epoch time) or as Date objects.

      await Deno.utime("myfile.txt", 1556495550, new Date());

    Parameters

    • filename: string
    • atime: number | Date
    • mtime: number | Date

    Returns Promise<void>

utimeSync

  • utimeSync(filename: string, atime: number | Date, mtime: number | Date): void
  • Synchronously changes the access and modification times of a file system object referenced by filename. Given times are either in seconds (Unix epoch time) or as Date objects.

      Deno.utimeSync("myfile.txt", 1556495550, new Date());

    Parameters

    • filename: string
    • atime: number | Date
    • mtime: number | Date

    Returns void

write

  • write(rid: number, p: Uint8Array): Promise<number>
  • Write to the file ID the contents of the array buffer.

    Resolves with the number of bytes written.

     (async () => {
       const encoder = new TextEncoder();
       const data = encoder.encode("Hello world\n");
       const file = await Deno.open("/foo/bar.txt");
       await Deno.write(file.rid, data);
     })();

    Parameters

    • rid: number
    • p: Uint8Array

    Returns Promise<number>

writeAll

  • writeAll(w: Writer, arr: Uint8Array): Promise<void>

writeAllSync

  • writeAllSync(w: SyncWriter, arr: Uint8Array): void

writeFile

  • writeFile(filename: string, data: Uint8Array, options?: WriteFileOptions): Promise<void>
  • Write a new file, with given filename and data.

      const encoder = new TextEncoder();
      const data = encoder.encode("Hello world\n");
      await Deno.writeFile("hello.txt", data);

    Parameters

    Returns Promise<void>

writeFileSync

  • writeFileSync(filename: string, data: Uint8Array, options?: WriteFileOptions): void
  • Write a new file, with given filename and data synchronously.

      const encoder = new TextEncoder();
      const data = encoder.encode("Hello world\n");
      Deno.writeFileSync("hello.txt", data);

    Parameters

    Returns void

writeSync

  • writeSync(rid: number, p: Uint8Array): number
  • Write synchronously to the file ID the contents of the array buffer.

    Resolves with the number of bytes written.

      const encoder = new TextEncoder();
      const data = encoder.encode("Hello world\n");
      const file = Deno.openSync("/foo/bar.txt");
      Deno.writeSync(file.rid, data);

    Parameters

    • rid: number
    • p: Uint8Array

    Returns number

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc