Access the home directory in Deno
If you want to access the home directory from you Deno program, you can use the
get method with
In unix environments, returns a string along the lines of
So if you want to write a script that accesses a configuration file like
.bashrc, you could read the file with:
const bashConfig = Deno.readTextFileSync(
Deno.env.get("HOME") + "/.bashrc"
Since we are accessing
Deno.env, we need to run the program with the
deno run --allow-env read-bashrc.ts
Here is a Repl where you can play around with accessing the home directory in Deno.