Deno World
Published in

Deno World

Deno nuggets: Disable permission prompting

This article is a part of the Deno nuggets series, where each article attempts to suggest a pointed solution to a specific question that can be read in less than a minute. There is no ordering of nuggets.

Problem

How to disable the default permission prompting while running Deno applications?

// app.ts
await Deno.readTextFile("./testdata/sample.txt");
// --> deno run app.ts
⚠️ ️Deno requests read access to "./testdata/sample.txt". Run again with --allow-read to bypass this prompt.
Allow? [y/n (y = yes allow, n = no deny)]

Solution

The default behavior of permission prompting is perhaps good while development, but surely not recommended for production applications. Once disabled, a PermissionDeniedError would be raised instead of prompting the user for permissions.

There are two ways to disable permission prompting:

  • Disable globally using environment variable DENO_NO_PROMPT (this can be set in the user profile)
> export DENO_NO_PROMPT=1> deno run app.ts error: Uncaught (in promise) PermissionDenied: Requires read access to "./testdata/sample.txt", run again with the --allow-read flag
await Deno.readTextFile("./testdata/sample.txt");
^
at async Object.readTextFile (deno:runtime/js/40_read_file.js:55:20)
at async file:///Users/mayankc/Work/source/denoExamples/app.ts:1:1
  • Disable locally using — no-prompt option
> deno run --no-prompt app.ts 
error: Uncaught (in promise) PermissionDenied: Requires read access to "./testdata/sample.txt", run again with the --allow-read flag
await Deno.readTextFile("./testdata/sample.txt");
^
at async Object.readTextFile (deno:runtime/js/40_read_file.js:55:20)
at async file:///Users/mayankc/Work/source/denoExamples/app.ts:1:1

This story is a part of the exclusive medium publication on Deno: Deno World.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store