@hodfords/env-parser
Env-Parser is a simple and lightweight library for parsing environment variables in Node.js applications. Inspired by znv but simpler and lighter.
Installation 🤖​
To begin using it, we first install the required dependencies.
npm install @hodfords/env-parser
Usage 🚀​
Create .env
file, you can also pass it via environment variable without creating a file.
APP_PORT=3000
REDIS_PORT=6379
REDIS_HOST=localhost
ALLOW_SEND_MAIL=true
Create env file like env.ts
and import parse
and z
from @hodfords/env-parser
.
import { parse, z } from '@hodfords/env-parser';
export const env = parse(process.env, {
APP_PORT: z.number().min(1000).max(9999),
REDIS: {
PORT: z.number().default(6379),
HOST: z.string().default('localhost')
},
ALLOW_SEND_MAIL: z.boolean().default(true)
});
Note: env-parser supports multiple parser levels, but we recommend using up to 2 levels to ensure easier code readability.
More validation function here: Zod Validation
License​
This project is licensed under the MIT License