제로 의존성 TypeScript env 유효성 검사기를 구축했습니다.

작성자

카테고리:

← 피드로
DEV Community · giannielloemmanuele-lgtm · 2026-06-29 개발(SW)

giannielloemmanuele-lgtm

Every Node.js developer has been burned by this at least once:

const port = parseInt(process.env.PORT); // NaN if PORT is missing
const db = process.env.DATABASE_URL;     // string | undefined — not safe!

Enter fullscreen mode Exit fullscreen mode

Your app starts fine locally, then crashes in production because someone forgot to set an env var. The error shows up 3 hours later, not at startup.

The solution

I built @harmand66/typesafe-env — a tiny, zero-dependency library that validates and types your environment variables at boot time.

import { createEnv } from '@harmand66/typesafe-env';

const env = createEnv({
  PORT:         { type: 'number',  default: 3000 },
  DATABASE_URL: { type: 'string',  required: true },
  DEBUG:        { type: 'boolean', default: false },
});

// ✅ TypeScript knows PORT is a number
env.PORT + 1     // 3001 — not "30001"
env.DATABASE_URL // string — guaranteed, never undefined

Enter fullscreen mode Exit fullscreen mode

If anything is missing or wrong, your app fails immediately at startup with a clear message:
All errors at once — no more fixing them one by one.

Why not Zod?

Zod is great but it’s 57kb and requires a lot of boilerplate for this specific use case. @harmand66/typesafe-env is zero dependencies and does one thing well.

Try it

npm install @harmand66/typesafe-env

Enter fullscreen mode Exit fullscreen mode

GitHub: https://github.com/giannielloemmanuele-lgtm/typesafe-env
npm: https://www.npmjs.com/package/@harmand66/typesafe-env

Would love any feedback or contributions! 🙏

원문에서 계속 ↗

코멘트

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다