I've seen that Deno.env seems to get an information about my PC and some path.
But where does it knows it from? How do I able to fill my own .env file?
I've seen that Deno.env seems to get an information about my PC and some path.
But where does it knows it from? How do I able to fill my own .env file?
The information contained in Deno.env is the same that was provided in Node.js.
These variables are called environment variables.
https://nodejs.org/dist/latest-v8.x/docs/api/process.html#process_process_env
http://man7.org/linux/man-pages/man7/environ.7.html
This is classical for a CLI (like deno) to access user environment variables.
Now if you are trying to fill your environment variables, from an .env file, you need something like this:
You can display more information about your Deno.env by running this:
$ deno eval "console.log(Deno.env.toObject())"
OR
// file.ts
console.log(Deno.env.toObject())
https://doc.deno.land/https/github.com/denoland/deno/releases/latest/download/lib.deno.d.ts#Deno.env
Hope this helps!
If you want to fill your own .env you should use the dotenv/mod.ts package:
import { config } from "https://deno.land/x/dotenv/mod.ts";
const greeting = config().GREETING
console.log(greeting);
The .env file:
GREETING = Hello!
Check the documentation for all the options.
If we want to store our credentials or other data in .env file then it should be created at the root of your project folder(/my_deno_api/.env), then use package dotenv/load.ts
import "https://deno.land/x/dotenv/load.ts";
const jwt_key = Deno.env.get("JWT_KEY");
For more info check this documentation
Thanks,