Skip to main content
Deno.permissions - Deno documentation
variable Deno.permissions

Deno's permission management API.

It is a singleton instance of the Permissions object and is based on the web platform Permissions API, though some proposed parts of the API which are useful in a server side runtime context were removed or abandoned in the web platform specification which is why it was chosen to locate it in the Deno namespace instead.

By default, if the stdin/stdout is TTY for the Deno CLI (meaning it can send and receive text), then the CLI will prompt the user to grant permission when an un-granted permission is requested. This behavior can be changed by using the --no-prompt command at startup. When prompting the CLI will request the narrowest permission possible, potentially making it annoying to the user. The permissions APIs allow the code author to request a wider set of permissions at one time in order to provide a better user experience.

Requesting already granted permissions will not prompt the user and will return that the permission was granted.

Querying

const status = await Deno.permissions.query({ name: "read", path: "/etc" });
console.log(status.state);
const status = Deno.permissions.querySync({ name: "read", path: "/etc" });
console.log(status.state);

Revoking

import { assert } from "jsr:@std/assert";

const status = await Deno.permissions.revoke({ name: "run" });
assert(status.state !== "granted")
import { assert } from "jsr:@std/assert";

const status = Deno.permissions.revokeSync({ name: "run" });
assert(status.state !== "granted")

Requesting

const status = await Deno.permissions.request({ name: "env" });
if (status.state === "granted") {
  console.log("'env' permission is granted.");
} else {
  console.log("'env' permission is denied.");
}
const status = Deno.permissions.requestSync({ name: "env" });
if (status.state === "granted") {
  console.log("'env' permission is granted.");
} else {
  console.log("'env' permission is denied.");
}

Type