Deno.Permissions - Deno documentation
class Deno.Permissions

Deno's permission management API.

The class which provides the interface for the Deno.permissions global instance 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.

Methods

Resolves to the current status of a permission.

Note, if the permission is already granted, request() will not prompt the user again, therefore query() is only necessary if you are going to react differently existing permissions without wanting to modify them or prompt the user to modify them.

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

Returns the current status of a permission.

Note, if the permission is already granted, request() will not prompt the user again, therefore querySync() is only necessary if you are going to react differently existing permissions without wanting to modify them or prompt the user to modify them.

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

Requests the permission, and resolves to the state of the permission.

If the permission is already granted, the user will not be prompted to grant the permission again.

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

Requests the permission, and returns the state of the permission.

If the permission is already granted, the user will not be prompted to grant the permission again.

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

Revokes a permission, and resolves to the state of the permission.

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

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

Revokes a permission, and returns the state of the permission.

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

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