lagon icon indicating copy to clipboard operation
lagon copied to clipboard

RFC: Environment variables

Open QuiiBz opened this issue 2 years ago • 2 comments

Currently, environment variables are accessible with process.env, similar to Node.js. I came across an issue today with Lyra: to check if we are running in Node.js or an Edge runtime, they check if process !== undefined and then use an API that is available only on Node.js, but not on Lagon.

Using process.env to hold environment variables might be more challenging for external libraries to know in which environment they are running. Feel free to discuss your thoughts about this below.

For reference:

  • Deno Deploy uses Deno.env: https://doc.deno.land/deno/stable/~/Deno.env
  • Cloudflare Workers uses global variables: https://developers.cloudflare.com/workers/platform/environment-variables/

QuiiBz avatar Aug 22 '22 18:08 QuiiBz

TIL about CloudFlare supporting the global environment variables 😅 honestly I agree with process being undefined in workers as they are closer to a browser environment. That being said my suggestion would be to support import.meta.emv which ties in with ESM and suggesting folks who want process.env to use something like the replace plugin from rollup

JoviDeCroock avatar Jan 24 '23 12:01 JoviDeCroock

Great suggestion, I like it. Note that WinterCG might in the future define a unified way to access environment variables across all runtimes: https://github.com/wintercg/environment-metadata/issues/1

QuiiBz avatar Jan 24 '23 18:01 QuiiBz