-
Notifications
You must be signed in to change notification settings - Fork 0
Description
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 the env param:
export default {
fetch(request, env, context) {
// env.API_TOKEN
},
};Reference: https://developers.cloudflare.com/workers/runtime-apis/fetch-event/#syntax-module-worker
Vercel
Environment variables are defined on process.env object. For example, an API_TOKEN environment variable would be available by process.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, an API_TOKEN environment variable would be available by Deno.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, an API_TOKEN environment variable would be available by process.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, an API_TOKEN environment variable would be available by Oxygen.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 that import.meta is only available in ES Modules.