#environment variables issue
9 messages · Page 1 of 1 (latest)
yes, I'm primarily a python programmer which is why the filenames are in snake_case
I was able to get it working by adding the environment variable to the .bash_profile, but the red squiggle won't go away. Which is what I'm really here for.
That's a type issue.
You should change line 3 to
const stationId = Deno.env.get("nashuaStation") ?? "NOVALUE";
OR alternative write it like this const stationId = Deno.env.get("nashuaStation")!;
the ! tells the type system to comply
and then handle the error
Also, you don't need to add the env variables to your bash_profile.
You can instead use a .env file and write them in their like this
# .enn
export gh_token=blahblahblah
export AWS_ACCESS_KEY_ID="blahblahblah"
and then make sure to import the loader like so
import "https://deno.land/x/dotenv@v3.2.2/load.ts"
const GH_TOKEN = Deno.env.get("gh_token")!
TS takes a bit to get a hang of, but stick with it and you'll be just fine 🙂
Deno can't know if the environment variable you are looking for exists. So ts Deno.env.get("VAR_NAME"); returns string|undefined instead of just string.
Like @vapid magnet stated you could assert that the variable exists or check if it doesn't. You can also do that by inserting ts if(stationID == undefined) doSomeThing(); after you get the variables result but before calling getStationData