D
Deno

help

Safety measures (statically, not runtime) for libraries that require environment variables?

Aabi5/11/2023
Suppose I have a Deno library which expects certain environment variables to have been configured, otherwise a crash will happen. Does anyone know of a good way to somehow ensure at "compile-time" that whatever Deno application is using the library has configured these environment variables?
𝕒𝕣𝕤𝕙5/11/2023
but env vars will be read at runtime?
Aabi5/11/2023
@arshxcx yes, i know, it's a weird question, not sure why i'm even asking... i figured maybe i've missed something, maybe one could do some cool stuff using dotenv, maybe something involving weird type inference? i don't even know man.
𝕒𝕣𝕤𝕙5/11/2023
is your dev environment the same as your deployment environment?
Aabi5/11/2023
nah, not at all
𝕒𝕣𝕤𝕙5/11/2023
so you only want safety for the dev env
Aabi5/11/2023
well, i guess it's technically only possible for dev env... unless i'm missing something. right now, i use a zod schema which gets fed Deno.env.toObject(), so it will crash at startup. i'm just thinking maybe there's something more clever.
𝕒𝕣𝕤𝕙5/11/2023
well yeah its only possible for dev env, the alternative would be a type system that can predict the future if you want the put in the effort, you could have a script that periodically writes Deno.env to a .ts file and exports it as an object with as const you could dynamically import the file and you would have the exact types with exact values
Aabi5/11/2023
yeah, currently i'm experimenting with importing the environment configuration as a JSON import...
𝕒𝕣𝕤𝕙5/11/2023
yeah json works if you dont need to look at the values, json imports just give you keys
Aabi5/11/2023
ah, good point i'll try your idea, thanks for your input

Looking for more? Join the community!

Recommended Posts
Testing my Oak `Application` end-to-endI have an Oak application, and I'd like to test the main `const app = new Application()` configuratiAdding methods to Oak's Context?I am trying to figure out how to configure my Oak application/router so that my routes can do thingsClear cache modulesHello guys, I would like to know how can I remove unnecessary modules from cache? I've run - `denoHow does importing `node:https` work?Basically, how does it work? Does the machine need to have a Node.js environment installed for this?`await import()` without global executionHello there. This is some code from my `test.ts`:```ts // test.ts console.log("Hello World"); exportHTTPS custom cert passphrase in Deno?I have this code from a Node.js project, and I'm trying to figure out if there's any alternative in Increase http server timeout?How do i increase the timeout? Seems to be ~120 seconds by default, but we have longer running requeIs inspecting import.meta.url a reliable way to distinguish browser and deno contexts?I have been trying to figure out a good pattern to import JSON that will work whether called in denoFetching Twitter data with coroutines and puppeteerare there any recent examples of how to fetch Twitter data (like monitoring activity for a keyword ePathname prefix in serve()Hi, I was wondering if it's possible to only handle requests coming from specific prefix within pathembed typescript playground to web pagesome programming language guides like the rust book lets you directly edit and run code in their docUsing deno-lambda for AWS SAMI'm having issues trying to run deno-lambda (https://github.com/hayd/deno-lambda) locally. (I haven'How to monetize an app?I would like to monetize my apps in a certain way. Mabye limit some features. How to approach monetiStandard setup of a monorepo that includes frontend and backend TypeScript code for one appHello friends, I'm new to Deno and have what I feel is a relatively simple use case, but I've struggHow can I import https://github.com/ensdomains/ensjs-v3/tree/main in my denoThis is npm package. I want to use it in my deno project. How can I achive it? I am trying this: `imTesting that advanced types workI have a bunch of pretty advanced types, with generics and inferences all over the place. What woulHow can I reattach a debugger after disconnecting?I want to be able to start deno from a command line, but be able to attach to it from VSCode. I actPass string from TS to dll and return the passed string. (Like echo)Hey I am currently trying to understand the communication between a dll and my TS program. Currentlydeno-deploy limits on file storage?When deploying static files via deployctl, what are the storage limits / costs per GB? Couldn't findDoes anyone have a working OpenCL deno example?How can I use opencl with deno? Any examples?