-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Environment variables #1
Comments
Hourai.js (Winter @bytedance)Environment variables are retrived through a global
|
FWIW Cloudflare Workers has another syntax called module workers, in which environment variables are passed as an argument to the handler function instead of being placed globally. Reference: https://developers.cloudflare.com/workers/platform/environment-variables/#environmental-variables-with-module-workers, https://developers.cloudflare.com/workers/runtime-apis/fetch-event/#syntax-module-worker |
Something that scare me a little bit is that any sub dependency can get access to the enviorment variable that i'm using myself. any how you should not put secrets in process.env... here is why: https://diogomonica.com/2017/03/27/why-you-shouldnt-use-env-variables-for-secret-data/ heck why don't we even have a way to import secrets with á.la http import style: any way... i think putting things in they need to be sandboxed somehow. more secure & possible encrypted. |
@jimmywarting the concern makes sense. Though switching to a code But maybe whether or not secrets defined in environment variables isn't to be solved here? They are needed, and the goal here is to have a standard way to access them. |
@blittle do you mind editing the Cloudflare example in the issue? The syntax you used is deprecated and https://developers.cloudflare.com/workers/runtime-apis/fetch-event/#syntax-module-worker (env.VAR_NAME) should be used instead. |
Motivation
Platforms are not consistent in how they provide access to environment variables. We'd like to define a consistent API for environment variable access.
Environment variables on existing platforms
Cloudflare
Environment variables are injected into a scoped variable. For example, an
API_TOKEN
environment variable would be available within theenv
param:Reference: https://developers.cloudflare.com/workers/runtime-apis/fetch-event/#syntax-module-worker
Vercel
Environment variables are defined on
process.env
object. For example, anAPI_TOKEN
environment variable would be available byprocess.env.API_TOKEN
.Reference: https://vercel.com/docs/concepts/functions/serverless-functions#environment-variables
Deno
Environment variables are retrieved through a global
Deno.env
object. For example, anAPI_TOKEN
environment variable would be available byDeno.env.get('API_TOKEN')
Reference: https://doc.deno.land/deno/stable/~/Deno.env
NodeJS
Environment variables are defined on a global
process.env
object. For example, anAPI_TOKEN
environment variable would be available byprocess.env.API_TOKEN
.Reference: https://nodejs.org/docs/latest/api/process.html#processenv
Shopify Oxygen
Environment variables are defined on a global
Oxygen.env
object. For example, anAPI_TOKEN
environment variable would be available byOxygen.env.API_TOKEN
.Reference: https://shopify.dev/custom-storefronts/oxygen/environment-variables
Options
Unify on one of the existing platform implementations
Which one?
import.meta
The
import.meta
object exposes context-specific metadata to a JavaScript module. We could utilize that container for environment variables,import.meta.env.API_TOKEN
.There is precedent to
import.meta.env
with Vite's implementation. The downside to this is thatimport.meta
is only available in ES Modules.The text was updated successfully, but these errors were encountered: