
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
env-type-safe
Advanced tools
A type-safe environment variable manager for Node.js applications with built-in validation and TypeScript support.
.env files (using dotenv)npm install env-type-safe dotenv
Note: dotenv is a peer dependency and must be installed separately.
import { createEnvSafe } from 'env-type-safe';
// Define your environment schema
const env = createEnvSafe({
PORT: "number",
API_KEY: "string",
DEBUG: "boolean",
}, {
envFile: ".env" // Optional: path to .env file
});
// Type-safe access to variables
const port: number = env.get<number>("PORT"); // Returns number
const apiKey: string = env.get<string>("API_KEY"); // Returns string
const debug: boolean = env.get<boolean>("DEBUG"); // Returns boolean
// Get all variables at once
const allVars = env.getAll();
The package supports three types of environment variables:
| Type | Description | Example |
|---|---|---|
string | Any string value | API_KEY="xyz123" |
number | Numeric values (auto-converted from string) | PORT="3000" |
boolean | Boolean values (must be "true" or "false") | DEBUG="true" |
The package includes comprehensive error handling:
Missing Variables
// If DATABASE_URL is not defined:
createEnvSafe({ DATABASE_URL: "string" })
// Error: Environment variable DATABASE_URL is missing
Invalid Types
// If PORT="not-a-number" in .env:
createEnvSafe({ PORT: "number" })
// Error: Environment variable PORT must be a number
Invalid Boolean Values
// If DEBUG="yes" in .env:
createEnvSafe({ DEBUG: "boolean" })
// Error: Environment variable DEBUG must be 'true' or 'false'
Define Schema Once
// config/env.ts
export const envSchema = {
NODE_ENV: "string",
PORT: "number",
DEBUG: "boolean",
API_KEY: "string"
};
export const env = createEnvSafe(envSchema);
Use Type Inference
// TypeScript will infer the correct types
const { PORT, API_KEY, DEBUG } = env.getAll();
Environment File
PORT=3000
DEBUG=true
API_KEY=your-secret-key
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
git checkout -b feature/amazing-feature)git commit -m 'Add some amazing feature')git push origin feature/amazing-feature)MIT
MD Azadur Rahman
FAQs
A type-safe environment variable manager
We found that env-type-safe demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.