console.log(Deno.env.get('MY_SECRET'));Deno enforces security by requiring the --allow-env flag to access environment variables. Without it, accessing Deno.env.get() throws a PermissionDenied error.
deno run --allow-env=MY_VAR script.ts, what is the output?console.log(Deno.env.get('MY_VAR')); console.log(Deno.env.get('OTHER_VAR'));
--allow-env flag can specify which variables are accessible.The flag --allow-env=MY_VAR allows access only to MY_VAR. Accessing OTHER_VAR causes a PermissionDenied error.
deno run script.ts?const token = Deno.env.get('API_TOKEN'); console.log(`Token: ${token}`);
Deno requires the --allow-env flag to access environment variables. Without it, accessing Deno.env.get() throws a PermissionDenied error regardless of whether the variable is set.
USER and PATH?The --allow-env flag accepts a comma-separated list of variable names. Option C correctly uses --allow-env=USER,PATH.
Deno.permissions.request({ name: 'env', variable: 'SECRET' }). What is the expected behavior if the user denies the permission request?async function getSecret() { const status = await Deno.permissions.request({ name: 'env', variable: 'SECRET' }); if (status.state === 'granted') { return Deno.env.get('SECRET'); } else { return 'Permission denied'; } } getSecret().then(console.log);
The Deno.permissions.request() method returns a status object. If the user denies permission, the script can handle it gracefully and avoid runtime errors by checking the state.
