Options
All
  • Public
  • Public/Protected
  • All
Menu

Index

Enumerations

Classes

Interfaces

Type aliases

Variables

Functions

Type aliases

Arch

Arch: "x64" | "arm64"

ConsoleOptions

ConsoleOptions: Partial<object>

UNSTABLE: rename to InspectOptions

DirKind

DirKind: "home" | "cache" | "config" | "executable" | "data" | "data_local" | "audio" | "desktop" | "document" | "download" | "font" | "picture" | "public" | "template" | "video"

UNSTABLE

OpenMode

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

OperatingSystem

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

PermissionDescriptor

PermissionName

PermissionName: "run" | "read" | "write" | "net" | "env" | "plugin" | "hrtime"

UNSTABLE: potentially want names to overlap more with browser.

Permissions as granted by the caller See: https://w3c.github.io/permissions/#permission-registry

PermissionState

PermissionState: "granted" | "denied" | "prompt"

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.

Transport

Transport: "tcp"

Variables

Const EOF

EOF: unique symbol

UNSTABLE: might move to Deno.symbols UNSTABLE: might move to Deno.symbols

Const Signal

UNSTABLE: make platform independent.

Signals numbers. This is platform dependent.

Const args

args: string[]

Returns the script arguments to the program. If for example we run a program

deno --allow-read https://deno.land/std/examples/cat.ts /etc/passwd

Then Deno.args will contain just

[ "/etc/passwd" ]

Const build

build: BuildInfo

Let noColor

noColor: boolean

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

Const permissions

permissions: Permissions

UNSTABLE: maybe move to navigator.permissions to match web API.

Let pid

pid: number

The current process id of the runtime.

Const signals

signals: object

UNSTABLE new API.

Type declaration

  • alarm: function

    Returns the stream of SIGALRM signals. This method is the shorthand for Deno.signal(Deno.Signal.SIGALRM).

  • child: function

    Returns the stream of SIGCHLD signals. This method is the shorthand for Deno.signal(Deno.Signal.SIGCHLD).

  • hungup: function

    Returns the stream of SIGHUP signals. This method is the shorthand for Deno.signal(Deno.Signal.SIGHUP).

  • interrupt: function

    Returns the stream of SIGINT signals. This method is the shorthand for Deno.signal(Deno.Signal.SIGINT).

  • io: function

    Returns the stream of SIGIO signals. This method is the shorthand for Deno.signal(Deno.Signal.SIGIO).

  • pipe: function

    Returns the stream of SIGPIPE signals. This method is the shorthand for Deno.signal(Deno.Signal.SIGPIPE).

  • quit: function

    Returns the stream of SIGQUIT signals. This method is the shorthand for Deno.signal(Deno.Signal.SIGQUIT).

  • terminate: function

    Returns the stream of SIGTERM signals. This method is the shorthand for Deno.signal(Deno.Signal.SIGTERM).

  • userDefined1: function

    Returns the stream of SIGUSR1 signals. This method is the shorthand for Deno.signal(Deno.Signal.SIGUSR1).

  • userDefined2: function

    Returns the stream of SIGUSR2 signals. This method is the shorthand for Deno.signal(Deno.Signal.SIGUSR2).

  • windowChange: function

    Returns the stream of SIGWINCH signals. This method is the shorthand for Deno.signal(Deno.Signal.SIGWINCH).

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 symbols

symbols: object

UNSTABLE: new API. Maybe move EOF here.

Special Deno related symbols.

Type declaration

  • 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.

  • internal: keyof symbol

    Symbol to access exposed internal Deno API

Const version

version: Version

Functions

applySourceMap

  • UNSTABLE: new API, not yet vetted.

    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

bundle

  • bundle(rootName: string, sources?: Record<string, string>, options?: CompilerOptions): Promise<[Diagnostic | undefined, string]>
  • UNSTABLE: new API, yet to be vetted.

    Takes a root module name, and optionally a record set of sources. Resolves with a single JavaScript string that is like the output of a deno bundle command. If just a root name is provided, the modules will be resolved as if the root module had been passed on the command line.

    If sources are passed, all modules will be resolved out of this object, where the key is the module name and the value is the content. The extension of the module name will be used to determine the media type of the module.

     const [ maybeDiagnostics1, output1 ] = await Deno.bundle("foo.ts");
    
     const [ maybeDiagnostics2, output2 ] = await Deno.bundle("/foo.ts", {
       "/foo.ts": `export * from "./bar.ts";`,
       "/bar.ts": `export const bar = "bar";`
     });

    Parameters

    • rootName: string

      The root name of the module which will be used as the "starting point". If no sources is specified, Deno will resolve the module externally as if the rootName had been specified on the command line.

    • Optional sources: Record<string, string>

      An optional key/value map of sources to be used when resolving modules, where the key is the module name, and the value is the source content. The extension of the key will determine the media type of the file when processing. If supplied, Deno will not attempt to resolve any modules externally.

    • Optional options: CompilerOptions

      An optional object of options to send to the compiler. This is a subset of ts.CompilerOptions which can be supported by Deno.

    Returns Promise<[Diagnostic | undefined, string]>

chdir

  • chdir(directory: string): void
  • UNSTABLE: maybe needs permissions.

    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);

    Needs allow-write

    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);

    Needs allow-write

    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.

    Needs allow-write permission.

    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.

    Needs allow-write permission.

    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

compile

  • compile(rootName: string, sources?: Record<string, string>, options?: CompilerOptions): Promise<[Diagnostic | undefined, Record<string, string>]>
  • UNSTABLE: new API, yet to be vetted.

    Takes a root module name, any optionally a record set of sources. Resolves with a compiled set of modules. If just a root name is provided, the modules will be resolved as if the root module had been passed on the command line.

    If sources are passed, all modules will be resolved out of this object, where the key is the module name and the value is the content. The extension of the module name will be used to determine the media type of the module.

     const [ maybeDiagnostics1, output1 ] = await Deno.compile("foo.ts");
    
     const [ maybeDiagnostics2, output2 ] = await Deno.compile("/foo.ts", {
       "/foo.ts": `export * from "./bar.ts";`,
       "/bar.ts": `export const bar = "bar";`
     });

    Parameters

    • rootName: string

      The root name of the module which will be used as the "starting point". If no sources is specified, Deno will resolve the module externally as if the rootName had been specified on the command line.

    • Optional sources: Record<string, string>

      An optional key/value map of sources to be used when resolving modules, where the key is the module name, and the value is the source content. The extension of the key will determine the media type of the file when processing. If supplied, Deno will not attempt to resolve any modules externally.

    • Optional options: CompilerOptions

      An optional object of options to send to the compiler. This is a subset of ts.CompilerOptions which can be supported by Deno.

    Returns Promise<[Diagnostic | undefined, Record<string, string>]>

connect

connectTLS

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");

    Needs allow-read and allow-write permissions.

    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");

    Needs allow-read and allow-write permissions.

    Parameters

    • from: string
    • to: string

    Returns void

create

  • create(filename: string): Promise<File>
  • Creates a file if none exists or truncates an existing file and returns an instance of the File object.

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

    Requires allow-read and allow-write.

    Parameters

    • filename: string

    Returns Promise<File>

createSync

  • createSync(filename: string): File
  • Creates a file if none exists or truncates an existing file and returns an instance of the File object synchronously.

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

    Requires allow-read and allow-write.

    Parameters

    • filename: string

    Returns File

cwd

  • cwd(): string
  • UNSTABLE: maybe needs permissions.

    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

dir

  • dir(kind: DirKind): string | null
  • UNSTABLE: Might rename method dir and type alias DirKind.

    Returns the user and platform specific directories. Requires the --allow-env flag. Returns null if there is no applicable directory or if any other error occurs.

    Argument values: "home", "cache", "config", "executable", "data", "data_local", "audio", "desktop", "document", "download", "font", "picture", "public", "template", "video"

    "cache" |Platform | Value | Example | | ------- | ----------------------------------- | ---------------------------- | | Linux | $XDG_CACHE_HOME or $HOME/.cache | /home/alice/.cache | | macOS | $HOME/Library/Caches | /Users/Alice/Library/Caches | | Windows | {FOLDERID_LocalAppData} | C:\Users\Alice\AppData\Local |

    "config" |Platform | Value | Example | | ------- | ------------------------------------- | -------------------------------- | | Linux | $XDG_CONFIG_HOME or $HOME/.config | /home/alice/.config | | macOS | $HOME/Library/Preferences | /Users/Alice/Library/Preferences | | Windows | {FOLDERID_RoamingAppData} | C:\Users\Alice\AppData\Roaming |

    "executable" |Platform | Value | Example | | ------- | --------------------------------------------------------------- | -----------------------| | Linux | XDG_BIN_HOME or $XDG_DATA_HOME/../bin or $HOME/.local/bin | /home/alice/.local/bin | | macOS | - | - | | Windows | - | - |

    "data" |Platform | Value | Example | | ------- | ---------------------------------------- | ---------------------------------------- | | Linux | $XDG_DATA_HOME or $HOME/.local/share | /home/alice/.local/share | | macOS | $HOME/Library/Application Support | /Users/Alice/Library/Application Support | | Windows | {FOLDERID_RoamingAppData} | C:\Users\Alice\AppData\Roaming |

    "data_local" |Platform | Value | Example | | ------- | ---------------------------------------- | ---------------------------------------- | | Linux | $XDG_DATA_HOME or $HOME/.local/share | /home/alice/.local/share | | macOS | $HOME/Library/Application Support | /Users/Alice/Library/Application Support | | Windows | {FOLDERID_LocalAppData} | C:\Users\Alice\AppData\Local |

    "audio" |Platform | Value | Example | | ------- | ------------------ | -------------------- | | Linux | XDG_MUSIC_DIR | /home/alice/Music | | macOS | $HOME/Music | /Users/Alice/Music | | Windows | {FOLDERID_Music} | C:\Users\Alice\Music |

    "desktop" |Platform | Value | Example | | ------- | -------------------- | ---------------------- | | Linux | XDG_DESKTOP_DIR | /home/alice/Desktop | | macOS | $HOME/Desktop | /Users/Alice/Desktop | | Windows | {FOLDERID_Desktop} | C:\Users\Alice\Desktop |

    "document" |Platform | Value | Example | | ------- | ---------------------- | ------------------------ | | Linux | XDG_DOCUMENTS_DIR | /home/alice/Documents | | macOS | $HOME/Documents | /Users/Alice/Documents | | Windows | {FOLDERID_Documents} | C:\Users\Alice\Documents |

    "download" |Platform | Value | Example | | ------- | ---------------------- | ------------------------ | | Linux | XDG_DOWNLOAD_DIR | /home/alice/Downloads | | macOS | $HOME/Downloads | /Users/Alice/Downloads | | Windows | {FOLDERID_Downloads} | C:\Users\Alice\Downloads |

    "font" |Platform | Value | Example | | ------- | ---------------------------------------------------- | ------------------------------ | | Linux | $XDG_DATA_HOME/fonts or $HOME/.local/share/fonts | /home/alice/.local/share/fonts | | macOS | $HOME/Library/Fonts | /Users/Alice/Library/Fonts | | Windows | – | – |

    "picture" |Platform | Value | Example | | ------- | --------------------- | ----------------------- | | Linux | XDG_PICTURES_DIR | /home/alice/Pictures | | macOS | $HOME/Pictures | /Users/Alice/Pictures | | Windows | {FOLDERID_Pictures} | C:\Users\Alice\Pictures |

    "public" |Platform | Value | Example | | ------- | --------------------- | ------------------- | | Linux | XDG_PUBLICSHARE_DIR | /home/alice/Public | | macOS | $HOME/Public | /Users/Alice/Public | | Windows | {FOLDERID_Public} | C:\Users\Public |

    "template" |Platform | Value | Example | | ------- | ---------------------- | ---------------------------------------------------------- | | Linux | XDG_TEMPLATES_DIR | /home/alice/Templates | | macOS | – | – | | Windows | {FOLDERID_Templates} | C:\Users\Alice\AppData\Roaming\Microsoft\Windows\Templates |

    "video" |Platform | Value | Example | | ------- | ------------------- | --------------------- | | Linux | XDG_VIDEOS_DIR | /home/alice/Videos | | macOS | $HOME/Movies | /Users/Alice/Movies | | Windows | {FOLDERID_Videos} | C:\Users\Alice\Videos |

    Parameters

    Returns string | null

env

  • env(): object
  • env(key: string): string | undefined
  • 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
  • Returns the value of an environment variable at invocation. If the variable is not present, undefined will be returned.

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

    Parameters

    • key: string

    Returns string | undefined

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

hostname

  • hostname(): string
  • Get the hostname. Requires the --allow-env flag.

      console.log(Deno.hostname());

    Returns string

inspect

  • UNSTABLE: ConsoleOptions rename to InspectOptions. Also the exact form of string output subject to change.

    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
  • UNSTABLE: the signo parameter maybe shouldn't be number.

    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.

    Currently no-op on Windows. TODO Should throw on windows instead of silently succeeding.

    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");

    Requires allow-read and allow-write permissions.

    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");

    Requires allow-read and allow-write permissions.

    Parameters

    • oldname: string
    • newname: string

    Returns void

listen

listenTLS

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());

    Requires allow-read permission.

    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());

    Requires allow-read permission.

    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' });

    Requires allow-write.

    Parameters

    Returns Promise<string>

makeTempDirSync

  • makeTempDirSync is the synchronous version of makeTempDir.

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

    Requires allow-write.

    Parameters

    Returns string

metrics

  • UNSTABLE: potentially broken.

    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, options?: MkdirOption): Promise<void>
  • 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", { recursive: true });

    Requires allow-write.

    Parameters

    Returns Promise<void>

  • Deprecated

    Parameters

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

    Returns Promise<void>

mkdirSync

  • mkdirSync(path: string, options?: MkdirOption): void
  • 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", { recursive: true });

    Requires allow-write.

    Parameters

    Returns void

  • Deprecated

    Parameters

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

    Returns void

open

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

    const file = await Deno.open("/foo/bar.txt", { read: true, write: true });

    Requires allow-read or allow-write or both depending on mode.

    Parameters

    Returns Promise<File>

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

    const file = await Deno.open("/foo/bar.txt, "w+");

    Requires allow-read or allow-write or both depending on mode.

    Parameters

    • filename: string
    • Optional mode: OpenMode

    Returns Promise<File>

openPlugin

  • openPlugin(filename: string): Plugin
  • UNSTABLE: New API, not yet vetted.

    Open and initalize a plugin. Requires the --allow-plugin flag.

       const plugin = Deno.openPlugin("./path/to/some/plugin.so");
       const some_op = plugin.ops.some_op;
       const response = some_op.dispatch(new Uint8Array([1,2,3,4]));
       console.log(`Response from plugin ${response}`);

    Parameters

    • filename: string

    Returns Plugin

openSync

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

      const file = Deno.openSYNC("/foo/bar.txt", { read: true, write: true });

    Requires allow-read or allow-write or both depending on mode.

    Parameters

    Returns File

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

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

    Requires allow-read or allow-write or both depending on mode.

    Parameters

    • filename: string
    • Optional mode: OpenMode

    Returns File

read

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

    Resolves with the number | EOF for the operation.

      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 | unique symbol>

readAll

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

readAllSync

readDir

  • readDir(path: string): Promise<FileInfo[]>
  • UNSTABLE: Unstable rename to readdir. Maybe need to return AsyncIterable.

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

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

    Requires allow-read.

    Parameters

    • path: string

    Returns Promise<FileInfo[]>

readDirSync

  • UNSTABLE: Unstable rename to readdirSync.

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

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

    Requires allow-read.

    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));

    Requires allow-read.

    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));

    Requires allow-read.

    Parameters

    • filename: string

    Returns Uint8Array

readSync

  • readSync(rid: number, p: Uint8Array): number | unique symbol
  • 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 | unique symbol

readlink

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

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

    Requires allow-read.

    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");

    Requires allow-read.

    Parameters

    • name: string

    Returns string

realpath

  • realpath(path: string): Promise<string>
  • Returns absolute normalized path with symbolic links resolved.

      const realPath = await Deno.realpath("./some/path");

    Requires allow-read.

    Parameters

    • path: string

    Returns Promise<string>

realpathSync

  • realpathSync(path: string): string
  • Returns absolute normalized path with symbolic links resolved synchronously.

      const realPath = Deno.realpathSync("./some/path");

    Requires allow-read.

    Parameters

    • path: 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});

    Requires allow-write permission.

    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});

    Requires allow-write permission.

    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");

    Requires allow-read and allow-write.

    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");

    Requires allow-read and allow-write.

    Parameters

    • oldpath: string
    • newpath: string

    Returns void

resources

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

shutdown

  • UNSTABLE: Maybe should remove how parameter maybe remove ShutdownMode entirely.

    Shutdown socket send and receive operations.

    Matches behavior of POSIX shutdown(3).

      const listener = Deno.listen({ port: 80 });
      const conn = await listener.accept();
      Deno.shutdown(conn.rid, Deno.ShutdownMode.Write);

    Parameters

    Returns void

signal

  • UNSTABLE new API.

    Returns the stream of the given signal number. You can use it as an async iterator.

    for await (const _ of Deno.signal(Deno.Signal.SIGTERM)) {
      console.log("got SIGTERM!");
    }

    You can also use it as a promise. In this case you can only receive the first one.

    await Deno.signal(Deno.Signal.SIGTERM);
    console.log("SIGTERM received!")

    If you want to stop receiving the signals, you can use .dispose() method of the signal stream object.

    const sig = Deno.signal(Deno.Signal.SIGTERM);
    setTimeout(() => { sig.dispose(); }, 5000);
    for await (const _ of sig) {
      console.log("SIGTERM!")
    }

    The above for-await loop exits after 5 seconds when sig.dispose() is called.

    Parameters

    • signo: number

    Returns SignalStream

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());

    Requires allow-read permission.

    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());

    Requires allow-read permission.

    Parameters

    • filename: string

    Returns FileInfo

symlink

  • symlink(oldname: string, newname: string, type?: string): Promise<void>
  • UNSTABLE type argument may be changed to "dir" | "file"

    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");

    Requires allow-read and allow-write permissions.

    Parameters

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

    Returns Promise<void>

symlinkSync

  • symlinkSync(oldname: string, newname: string, type?: string): void
  • UNSTABLE type argument may be changed to "dir" | "file"

    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");

    Requires allow-read and allow-write permissions.

    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>

transpileOnly

  • UNSTABLE: new API, yet to be vetted.

    Takes a set of TypeScript sources and resolves with a map where the key was the original file name provided in sources and the result contains the source and optionally the map from the transpile operation. This does no type checking and validation, it effectively "strips" the types from the file.

     const results =  await Deno.transpileOnly({
       "foo.ts": `const foo: string = "foo";`
     });

    Parameters

    • sources: Record<string, string>

      A map where the key is the filename and the value is the text to transpile. The filename is only used in the transpile and not resolved, for example to fill in the source name in the source map.

    • Optional options: CompilerOptions

      An option object of options to send to the compiler. This is a subset of ts.CompilerOptions which can be supported by Deno. Many of the options related to type checking and emitting type declaration files will have no impact on the output.

    Returns Promise<Record<string, TranspileOnlyResult>>

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);

    Requires allow-write.

    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);

    Requires allow-write.

    Parameters

    • name: string
    • Optional len: number

    Returns void

utime

  • utime(filename: string, atime: number | Date, mtime: number | Date): Promise<void>
  • UNSTABLE: needs investigation into high precision time.

    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());

    Requires allow-write.

    Parameters

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

    Returns Promise<void>

utimeSync

  • utimeSync(filename: string, atime: number | Date, mtime: number | Date): void
  • UNSTABLE: needs investigation into high precision time.

    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());

    Requires allow-write.

    Parameters

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

    Returns void

write

  • write(rid: number, p: Uint8Array): Promise<number>
  • Write to the resource 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 = 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);

    Requires allow-write and allow-read if create is false.

    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);

    Requires allow-write and allow-read if create is false.

    Parameters

    Returns void

writeSync

  • writeSync(rid: number, p: Uint8Array): number
  • Write synchronously to the resource 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