In order to pass command options to deno
via env
, you need the -S
parameter for env.
For example, the following is the minimal shebang you should use for self-running a script with Deno.
#!/usr/bin/env -S deno run
Complex Example:
The following script/shebang will run Deno as silently as possible, with all permissions and will assume there is an import_map.json
file next to the script file.
#!/usr/bin/env -S deno -q run --allow-all --import-map="${_}/../import_map.json"
// get file and directory name
const __filename = import.meta.url.replace("file://", "");
const __dirname = __filename.split("/").slice(0, -1).join("/");
The lines with __filename
and __dirname
will give you variables similar to Node's execution.
Script Installer
Deno also provides a convenient method for installing a script with it's permissions and dependencies in the configured distribution location.
See: Deno Manual - Script installer
Stand-Alone Executable
As of Deno 1.6, you can now build stand-alone executables from your script as well.
See: Deno Manual - Compiler - Compiling Executables