@atom-forge/env-reader · Configuration
Env Reader turns string-based environment variables into explicitly typed application values. Each field chooses its own parser and default, so missing or invalid configuration stops the application before it accepts work.
What it is
Call the reader’s methods while building startup configuration: string, int, float, boolean, oneOf, url, regex and list, plus file and dir for paths resolved against the project root. A missing variable without a default throws immediately.
The package does not infer a schema from an environment file and does not load .env files for you; loading belongs to your runtime or deployment.
Every value says what it is and what its default is. The configuration object is something you can read and review.
asReadonly gives a DeepReadonly TypeScript view at zero runtime cost. It does not freeze the object.
file and dir resolve against the project root and, by default, refuse to leave it.
Pass an absolute project-root path to EnvReader.
Choose a parser and, only where it is a policy decision, a default.
Pass the configuration into services instead of reading process.env across business code.
An honest fit check
The configuration object, parsing choices and defaults are written by hand.
Never serialize server secrets into browser-visible state, and do not silently default a required production secret.
Pass an absolute application project-root path; environment loading is application-owned.
import { EnvReader, asReadonly } from '@atom-forge/env-reader';
export function readConfig(projectRoot: string) {
const env = new EnvReader(projectRoot);
return asReadonly({
app: { environment: env.oneOf('APP_ENV', ['dev', 'prod', 'test'], 'prod') },
database: {
connectionString: env.string('DATABASE_URL'),
maxPool: env.int('DB_POOL_MAX', 20),
},
auth: { secret: env.string('JWT_SECRET') },
});
}