D
Deno

help

Environment Variable always returns undefined

Jjose12/29/2023
I'm just trying to import the values from dotenv to the code, but it always returns undefined. deno version: 1.39.1 running command: deno run --allow-read --allow-env main.ts dotenv content:
FOO=123
FOO=123
main.ts content:
import "https://deno.land/std@0.208.0/dotenv/load.ts";
console.log(Deno.env.get("FOO"));
import "https://deno.land/std@0.208.0/dotenv/load.ts";
console.log(Deno.env.get("FOO"));
I also tried
import { load } from "https://deno.land/std@0.210.0/dotenv/mod.ts";

await load({
export:true,
envPath: "./.env",
allowEmptyValues: false,
});

const test = Deno.env.get("TEST_TOKEN")
console.log(test)
import { load } from "https://deno.land/std@0.210.0/dotenv/mod.ts";

await load({
export:true,
envPath: "./.env",
allowEmptyValues: false,
});

const test = Deno.env.get("TEST_TOKEN")
console.log(test)
result is always:
Task start deno run --allow-read --allow-env main.ts
undefined
Task start deno run --allow-read --allow-env main.ts
undefined
Update: also tried deno run --env --allow-env main.ts and it still is undefined.
Iiuioiua12/29/2023
Firstly, your .env file is formatted incorrectly. It should be FOO=123. Secondly, use the —env CLI argument instead of load(). I.e. deno run —env main.ts
Jjose12/29/2023
Oh sorry, I writed it wrongly on the message, actually the file have = instead of : Still importing dotenv in main.ts?
Iiuioiua12/29/2023
Deno Blog
Deno 1.38: HTML doc generator and HMR
Deno 1.38 ships with HTML doc output, hot module replacement, improved Node.js compatibility by allowing you to use your own node_modules folder, and more.
Jjose12/29/2023
Thankss somehow, still getting undefined
Iiuioiua12/29/2023
Are you able to share the repo?
Jjose12/29/2023
yes, ill put it in github just a sec
Jjose12/29/2023
not a second lmao but here it is https://github.com/nogalogg/denotest
GitHub
GitHub - nogalogg/denotest
Contribute to nogalogg/denotest development by creating an account on GitHub.
ASAntonio Sampaio12/29/2023
youre trying to get TEST_TOKEN instead of FOO
Jjose12/29/2023
omg 😭
Iiuioiua12/29/2023
LOL! Yes, didn’t see that. I had a feeling it was a silly typo lol
ASAntonio Sampaio12/29/2023
and.... you're trying to log test instead of testgi
Jjose12/29/2023
oh that i must've writed when i was configuring git to publish it finally it worked lmaoo
ASAntonio Sampaio12/29/2023
<:deno_it_works:1181937887458111508> <:deno_thumbs_up:1181937842390319184>
Jjose12/29/2023
thank you sm

Looking for more? Join the community!

Recommended Posts
Updated examples for "Roll your own JavaScript runtime" blog posts?Hi all. I'd like to embed Deno in a project and I discovered the excellent series of "Roll your ownExecuting module multiple timesI have a script that can be imported using `await import()` statement. what goes inside brackets is Queues in production not workinghere's the main queue code , works locally ```ts import { getOneRepoPackageJson } from "./getOneRepoRemote KV access error : Missing DENO_KV_ACCESS_TOKEN environment variablei wen through the recomnded steps of adding a .env to the root of the project and adding ```sh DENODeno.serve() with SSL cert timeoutI have a very simple script that serves a `/ping` route. After some time (randomly) it stalls and noList kv items using a partial keyHey guys am trying to figure out kv and how to get stuffout of it how do i get iteme that have theIs there a recommended library to do dependency injection in Deno?I'm creating a Rest API with the repository and controllers pattern but my code in the `main.ts` filReact (CRA) deploy via denoGetting an error while building react CRA via deno deploy. Error: ENOENT: no such file or directoryCustom executable icon for `deno compile`?Is it possible to set a different icon rather than the default deno icon for the executable generateDeno.Command output as it runsHello, I am trying to run a command and have its output be logged as it runs , but for some reason telectrons using denoIn the recent deno version I see it is possible to runn executable in ./bin in node_modules using Cannot find moduleHi <:vmathi:812484657547313212> I'm trying to run a project with Deno, but i'm getting "Cannot find Uncaught error during deno deploy of vite appWhen creating a new vite app with vue and typescript I get this error message. This error is reprodDeno, TypeScript, ESBuild, WebGL, VSCodeHello! As the title suggests, I am using these technologies to create a web application: * Deno * TPossible issue with re-export compatibility with NodeIn https://github.com/japa/runner/issues/35, I have described an issue where Deno seems to be incompMake deno.serve handler asynchronousHow can i make the Deno.serve handler asynchronous? or like make it so that it can execute asynchronWhy my place.x -= 5 not working?At this part if(moveKey.right.pressed) { finishPostion += 5 quota exceededi hit the free limit tonight and upgraded to pro 20 minutes ago— when do my sites stop erroring withDeploying WASM via Deno Deploy Github ActionsHello, I'm trying to deploy a Leptos project that serves a .wasm bundle for the frontend, and uses Get only the first records with deno kv but reversed orderedI'm using Deno KV to store articles. Generating the ID for the articles: ``` export function genera