Env
@vitehub/env gives Vite and Nitro apps one place to declare environment variables, defaults, sources, and secret boundaries.
Use Env when configuration needs to be explicit and typed instead of scattered across process.env, import.meta.env, and provider dashboards.
import { env, envVite } from '@vitehub/env/vite'
import { defineConfig } from 'vite'
export default defineConfig({
plugins: [envVite({ prefix: 'VITEHUB_' })],
env: {
define: {
__APP_VERSION__: env({
mode: 'build',
source: env.packageJson('version'),
}),
},
public: {
appName: env({
default: 'ViteHub Env',
mode: 'build',
}),
},
},
})
import { env, envNitro } from '@vitehub/env/nitro'
import { defineNitroConfig } from 'nitro/config'
export default defineNitroConfig({
modules: [envNitro()],
env: {
auth: {
token: env({ secret: true }),
},
},
})
What Env solves
Environment values have different safety rules depending on when and where they are exposed.
Secret boundaries
Public Env
#vitehub/env/public.Server Env
#vitehub/env/server.Validation
Two configuration paths
Nitro handles server Runtime Env values. Use nested env declarations, then read the resolved object with useServerEnv().
Source model
Each env() declaration can read from:
- an inferred environment variable name
- an explicit environment variable through
env.source(name) package.jsonthroughenv.packageJson(path)- git branch or commit metadata
- a custom build-only resolver
Runtime declarations must be serializable. Custom sources and custom runtime schemas are build-only.
Start here
Start with Quickstart for a Vite public build value and a Nitro runtime secret. Use Usage when you need prefixes, nested config, custom sources, or diagnostics.

