Skip to content

franciscop/global-environment

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Environment variables across packages

Load the environment variables, no matter the runtime you are at:

import "global-environment";

const secret = process.env.SECRET;
console.log(secret);

It basically makes the process.env have the environment variables filled in Netlify Edge Functions and in Vite (we are open for contributions for other setups).

If you want them to load from your environment, make sure to call dotenv before global-environment:

import "dotenv/config";
import "global-environment";

Configuration

There's no configuration possible, it's just loading the variables from strange places into process. Basically this, but you don't need to type it in every project (or have a nightmare import setup):

if (typeof process === "undefined") {
  globalThis.process = {};
}
if (typeof globalThis.Netlify !== "undefined") {
  Object.assign(globalThis.process.env, globalThis.Netlify.env.toObject());
}
if (typeof import.meta.env !== "undefined") {
  Object.assign(globalThis.process.env, import.meta.env);
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published