Skip to content

Getting Started

Install nevr-env in your project:

sh
pnpm add nevr-env
sh
npm install nevr-env
sh
yarn add nevr-env
sh
bun add nevr-env

Basic Usage

nevr-env is framework agnostic — it works with Next.js, Vite, Express, Hono, Nuxt, Remix, Astro, SvelteKit, or any JavaScript runtime. Just set clientPrefix to match your framework and runtimeEnv to your env source.

Create a file env.ts (or env.js) in your project:

typescript
import { createEnv } from "nevr-env";
import { z } from "zod";

export const env = createEnv({
  server: {
    DATABASE_URL: z.string().url(),
    API_SECRET: z.string().min(32),
    NODE_ENV: z.enum(["development", "production", "test"]),
  },
  client: {
    NEXT_PUBLIC_API_URL: z.string().url(),
  },
  clientPrefix: "NEXT_PUBLIC_",
  runtimeEnv: process.env,
});

Now import and use your environment variables:

typescript
import { env } from "./env";

// ✅ Type-safe access
console.log(env.DATABASE_URL);  // string
console.log(env.NODE_ENV);      // "development" | "production" | "test"

// ❌ TypeScript error - doesn't exist
console.log(env.NONEXISTENT);

// ❌ Runtime error on client - server variable accessed in browser
console.log(env.API_SECRET);

Using Plugins

All official plugins are included with nevr-env - no extra installation needed:

typescript
import { createEnv, postgres, stripe } from "nevr-env";
import { z } from "zod";

export const env = createEnv({
  plugins: [
    postgres(),
    stripe({ webhook: true }),
  ],
  server: {
    NODE_ENV: z.enum(["development", "production", "test"]),
  },
  runtimeEnv: process.env,
});

// Access plugin variables with full type safety
console.log(env.DATABASE_URL);      // from postgres plugin
console.log(env.STRIPE_SECRET_KEY); // from stripe plugin

Available Plugins

check out the Plugins Overview for the full list of available plugins and their options.

Tree-Shaking with Subpath Imports

If you want to optimize bundle size, use subpath imports:

typescript
import { createEnv } from "nevr-env";
import { postgres } from "nevr-env/plugins/postgres";
import { stripe } from "nevr-env/plugins/stripe";

Interactive CLI Setup

Use the CLI wizard to set up environment variables:

sh
npx nevr-env init

The wizard will:

  1. Detect installed plugins
  2. Auto-discover values (e.g., Docker Postgres containers)
  3. Prompt for missing values
  4. Generate a .env file
  5. Create type-safe configuration

Next Steps

Released under the MIT License.