Repository navigation
Getting Started
Abhijeet Kumar edited this page Nov 20, 2026
·
1 revision
npm install env-saafenv-saaf has zero dependencies and works in plain CommonJS Node.js projects. TypeScript definitions are included.
Describe every variable your app needs, in one place:
const { validateEnv } = require('env-saaf');
const env = validateEnv({
PORT: { type: 'port', required: true },
DEBUG: { type: 'boolean', default: false },
API_URL: { type: 'url', required: true },
LOG_LEVEL: { type: 'string', choices: ['info', 'warn', 'error'], default: 'info' },
});If anything is missing or invalid, validateEnv throws one EnvSaafError listing all problems at once — at startup, not on the first production request.
const { loadEnv } = require('env-saaf');
const env = loadEnv({
PORT: { type: 'port', required: true },
});loadEnv reads .env from the working directory (or the paths you pass), supports ${VAR} interpolation and ${VAR:-default} fallbacks, multiline quoted values, and can load several files in order.
When you want the list of problems instead of an exception:
const { env, errors } = validateEnv(schema, process.env, { throwOnError: false });env holds every value that validated; errors holds the messages.
Next: CLI Guide · Types Reference
env-saaf Wiki
Español
- Home-es
- Getting-Started-es
- CLI-Guide-es
- Types-Reference-es
- FAQ-and-Troubleshooting-es
- Contributing-Guide-es
Português
- Home-pt-br
- Getting-Started-pt-br
- CLI-Guide-pt-br
- Types-Reference-pt-br
- FAQ-and-Troubleshooting-pt-br
- Contributing-Guide-pt-br
हिंदी
- Home-hi
- Getting-Started-hi
- CLI-Guide-hi
- Types-Reference-hi
- FAQ-and-Troubleshooting-hi
- Contributing-Guide-hi
简体中文
- Home-zh-cn
- Getting-Started-zh-cn
- CLI-Guide-zh-cn
- Types-Reference-zh-cn
- FAQ-and-Troubleshooting-zh-cn
- Contributing-Guide-zh-cn