Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where does `Deno.env` got its data from?

Tags:

deno

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?

like image 727
Irfandy Jip Avatar asked Apr 16 '26 06:04

Irfandy Jip


2 Answers

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:

https://deno.land/x/dotenv

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!

like image 93
cvng Avatar answered Apr 17 '26 18:04

cvng


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.

like image 23
Evandro Pomatti Avatar answered Apr 17 '26 18:04

Evandro Pomatti



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!