@rahil234/env-config
v1.0.2
Published
Load the environment variable and Validate the env described in 'env-config.js' file and create appropriate getters also with full type safety.
Maintainers
Readme
env-config
@rahil234/env-config is a utility package for loading environment variables and providing appropriate getters for them.
Features
- Load environment variables from
.envfiles. - validate environment variables against a configuration schema.
- Provide type-safe getters for environment variables.
- Simplify environment variable management in your projects.
Installation
npm install @rahil234/env-config
yarn add @rahil234/env-config
pnpm add @rahil234/env-config
bun add @rahil234/env-configUsage
Create a .env file in the root of your project:
PORT=3000
DATABASE_URL=mongodb://localhost:27017/mydbalso create an env-config.ts file in the root of your project:
{
"NODE_ENV": "NODE_ENV",
"PORT": "PORT"
}Use the env-config package in your project:
import { getEnv } from 'env-config';
const env = getEnv();
console.log(`Server running on port: ${env.port}`);
console.log(`Database URL: ${env.databaseUrl}`);If the specified environment variables are not set, the package will throw an error with a detailed message.
License
This project is licensed under the ISC License.
Author
rahil234
