Skip to content

Repository files navigation

env-proxy

uses proxies to simplify reading from process.env in node.

example

import{ConnectionOptions}from'@mikro-orm/core';importenvfrom'@rettgerst/env-proxy';letconnection: ConnectionOptions;// typed as boolean | undefinedconst{VERCEL}=env.bool;if(VERCEL){// typed as string, will throw if not definedconst{VERCEL_GIT_COMMIT_REF: branch,VERCEL_ENV: stage,DB_HOST: host,DB_USER: user,DB_PASSWORD: password}=env.required.string;// typed as number, parsed with parseInt, will throw if undefined or NaNconst{DB_PORT: port}=env.required.int;letdbName: string;if(stage==='production')dbName='myapp-production';elseif(stage==='preview')dbName=`myapp-preview-${branch}`;elseif(stage==='development')dbName=`myapp-dev-${branch}`;elsethrownewError(`Unrecognized vercel deployment stage ${stage}`);connection={ host, port, user, password, dbName };}else{const{DB_HOST: host='localhost'}=env.string;const{DB_USER: user,DB_PASSWORD: password}=env.required.string;connection={dbName: 'myapp',
host,
user,
password
};}

About

uses proxies to simplify reading from process.env in node

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages