envapt provides a robust way to read typed configuration values in TypeScript, effortlessly translating various sources like .env files and environment variables into precise types. With no runtime dependencies and built-in converters for multiple data types, it streamlines the configuration process across Node, Bun, Deno, and browser environments.

envapt
Type-safe Configuration Management
envapt offers a seamless way to manage configuration settings in TypeScript applications, allowing developers to read typed values from various sources while maintaining zero runtime dependencies. This makes it an ideal choice for projects requiring flexibility and robustness in configuration management.
Key Features:
- Typed Values: Retrieve configuration values in their exact type instead of the typical
string | undefined. A built-in fallback mechanism ensuresundefinedis not returned, enhancing type safety. - Versatile Sources: Easily read configurations from multiple sources, including
.envfiles,process.env, Cloudflare Workers bindings, browser bundles, or any custom object implementing areadVars()method. - Zero Runtime Dependencies: All components, including the value reader and converters, are self-contained, ensuring no additional dependencies clutter your project.
- Wide Compatibility: Works across various environments, including Node.js, Bun, Deno, Cloudflare Workers, and browsers. With support for Node
>=20, Bun>=1.3, and Deno>=2.5, this tool is built for portability. - Built-in .env Support for Node.js: Automatically handles loading
.envfiles with support for variable templates and strict checks, making setup straightforward.
Example Usage
To demonstrate the simplicity of using envapt in your code:
import { Envapter } from 'envapt';
const port = Envapter.getNumber('PORT', 3000); // Number retrieved as a typed value
For functional usage, values can be read as follows:
import { Envapter, Converters } from 'envapt';
const origins = Envapter.getUsing('ALLOWED_ORIGINS', Converters.array(), []);
For class property binding, the TC39 decorator syntax can be utilized:
import { EnvNum } from 'envapt';
class Config {
@EnvNum('PORT', 3000)
static accessor port: number;
}
Conclusion
envapt streamlines configuration management, making it easy to work with typesafe configurations across various platforms. For more detailed documentation, visit the official documentation.
No comments yet.
Sign in to be the first to comment.