Type-check environment variables against TypeScript schemas.
日本語版 README はこちら (Japanese README)
npm install -D @kobapi28/tsenv
# or
pnpm add -D @kobapi28/tsenv
# or
yarn add -D @kobapi28/tsenvCreate a TypeScript file that exports your environment variable schema:
// env.ts
type Env = {
API_URL: string
ASSET_URL: string
PORT?: number
DEBUG?: boolean
}
export default EnvCreate tsenv.config.js in your project root:
// tsenv.config.js
module.exports = {
schema: './env.ts', // Path to your type definition
files: ['./env/**'] // Glob patterns for env files to check
}Or if you're using TypeScript with tsx/ts-node:
// tsenv.config.ts
export default {
schema: './env.ts',
files: ['./env/**']
}npx tsenv checkYou can also specify a custom config file:
npx tsenv check -c ./custom-config.ts- ✅ Type checking for
string,number, andbooleantypes - ✅ Optional properties support (using
?) - ✅ Multiple env files support with glob patterns
- ✅ Clear error reporting with file locations
- ✅ Missing required variables detection
- ✅ Undefined variables detection
- ✅ Multiline environment variable support
- ✅ Error handling when no files match specified patterns
See the example directory for a complete working example.
Variables defined as required in the schema but not found in any env file.
Variables with values that don't match their expected types.
Variables found in env files but not defined in the schema.
MIT