0.3.0 • Published 1 year ago

@dotlouis/zenv v0.3.0

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

zenv

Parse and validate environment variables using zod

Installation

npm install -D zod @dotlouis/zenv

Note: zod package is required as a peer dependency.

Usage

import { z } from 'zod'
import { zenv } from '@dotlouis/zenv'

// be careful to pass a literal object to zenv and NOT a z.object()
const env = zenv(
  {
    DATABASE_URL: z.string().url(), // use zod type validators as  you would normaly
    DATABSE_SECERT: z
      .string()
      .describe('Get your secret at https://mydatabase.com/tokens'), // Add a description that will be displayed if the variable is missing or defaulted
    NEXT_PUBLIC_PORT: z.string().optional(),
    NEXT_PUBLIC_HOSTNAME: z.string().default('localhost'),
  },
  process.env, // optional, the variable to parse the schema against. By default zenv will scan process.env
  {
    // optional options
    publicPrefix: 'NEXT_PUBLIC_', // by default zenv mask all enviroment variable. Specify a prefix to display the variables (DON'T USE IT FOR SENSITIVE VARIABLES such as secrets)
  },
)

Example result

Notes

  • Be careful to pass a literal object {} to zenv() and NOT a z.object()
0.3.0

1 year ago

0.2.0

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago