npm package: @kushal124/env-manager
Description: A simple environment variable manager with CLI and web interface
Author: Kushal Khandelwal
Latest version: 1.0.0

# Environment Variable Manager 🔧

[![npm version](https://badge.fury.io/js/%40kushal124%2Fenv-manager.svg)](https://badge.fury.io/js/%40kushal124%2Fenv-manager)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
[![Node.js CI](https://github.com/kushal124/envman/workflows/Node.js%20CI/badge.svg)](https://github.com/kushal124/envman/actions)

A powerful, secure, and user-friendly environment variable manager with CLI and web interface. Perfect for developers juggling multiple projects, API keys, and configuration environments.

## ✨ Features

### 🔐 **Security First**
- **Encryption Support**: Encrypt sensitive variables with individual passwords or master password
- **Smart Masking**: Automatically masks sensitive values (API keys, tokens, passwords)
- **Secure Storage**: Variables stored locally with optional encryption
- **Password Validation**: Strong password requirements for encrypted variables

### 📁 **Profile Management**
- **Multiple Profiles**: Organize variables by project, environment, or client
- **Easy Switching**: Quick profile switching with context awareness
- **Session Tracking**: Load/unload variables in current shell session
- **Profile Metadata**: Add descriptions and track creation dates

### 🔄 **Import/Export System**
- **Multiple Formats**: JSON, dotenv, shell exports, key-value pairs, YAML
- **Auto-Detection**: Smart format detection for seamless imports
- **Bulk Operations**: Import hundreds of variables at once
- **Merge Support**: Combine with existing variables or replace entirely

### ⏰ **Advanced Features**
- **Variable Expiration**: Set TTL for temporary tokens and credentials
- **Cleanup Tools**: Automatically remove expired variables
- **Shell Integration**: Native support for bash, zsh, and fish
- **Web Interface**: Modern, responsive web UI for visual management
- **Session Management**: Track loaded variables across shell sessions

### 🌐 **Multi-Interface**
- **CLI**: Full-featured command-line interface
- **Web UI**: Clean, intuitive web interface at `http://localhost:3000`
- **REST API**: Complete API for integration with other tools

## 🚀 Quick Start

### Installation

#### Option 1: NPM (Recommended)
```bash
npm install -g @kushal124/env-manager
```

#### Option 2: Quick Install Script
```bash
curl -fsSL https://raw.githubusercontent.com/kushal124/envman/main/install.sh | bash
```

#### Option 3: Manual Installation
```bash
git clone https://github.com/kushal124/envman.git
cd env-manager
npm install && npm install -g .
```

### First Run Setup
```bash
envman setup
```

The setup wizard will guide you through:
1. Choosing storage location (`~/.env-manager/` recommended)
2. Setting up your first profile
3. Optional master password configuration

## 📖 Usage Guide

### Basic Operations

```bash
# Add variables to current profile
envman add OPENAI_API_KEY "sk-..." --encrypt
envman add DATABASE_URL "postgresql://localhost:5432/db"

# List all variables with smart masking
envman list

# Get a specific variable
envman get OPENAI_API_KEY --decrypt

# Remove variables
envman remove DATABASE_URL
```

### Profile Management

```bash
# Create profiles for different projects
envman profile create azure -d "Azure development environment"
envman profile create openai -d "OpenAI/ChatGPT projects"

# Switch between profiles
envman profile switch azure

# List all profiles with active indicator
envman profile list
● azure - Azure development environment  
○ openai - OpenAI/ChatGPT projects
○ default - Default profile

# View current profile status
envman profile current
```

### Advanced Variable Management

```bash
# Add encrypted variables with individual passwords
envman add STRIPE_SECRET_KEY "sk_test_..." --encrypt

# Add variables with expiration
envman add TEMP_TOKEN "temp_value" --expires 2h

# List variables showing encryption and expiration status
envman list
🔐 STRIPE_SECRET_KEY=[ENCRYPTED]
⏰ TEMP_TOKEN=temp_value (expires in 118m)
```

### Master Password System

```bash
# Set up master password for bulk encryption
envman master set

# Encrypt all current profile variables with master password
envman master encrypt-all

# Decrypt all master-encrypted variables
envman master decrypt-all

# Change master password (re-encrypts all variables)
envman master change
```

### Import/Export System

```bash
# Import from various formats (auto-detected)
echo 'export API_KEY="value"' | envman import
cat .env | envman import -f dotenv
curl -s https://api.example.com/config.json | envman import -f json

# Import to specific profile with merge
envman import -p production -m < production.env

# Preview imports without saving
echo '{"api": {"key": "value"}}' | envman import --dry-run

# Export for shell loading
eval "$(envman export)"
eval "$(envman export -p azure -s fish)"
```

### Session Management

```bash
# Load profile variables into current session
envman load azure

# Check what's currently loaded
envman status
Active profile: azure
Session ID: sess_abc123
Loaded profiles: azure, openai
Loaded variables (5):
  AZURE_CLIENT_ID (from azure)
  AZURE_CLIENT_SECRET (from azure)
  OPENAI_API_KEY (from openai)

# Unload specific profile or all variables
envman unload azure
envman unload
```

### Web Interface

```bash
# Start web interface
envman web

# Custom port
envman web -p 8080
```

Features in Web UI:
- 📊 **Dashboard**: Overview of all profiles and variables
- 🔧 **Variable Management**: Add, edit, delete with real-time validation
- 📁 **Profile Management**: Create, switch, delete profiles
- 📥 **Import Interface**: Drag-and-drop or paste variables
- 🔐 **Encryption Controls**: Encrypt/decrypt individual variables
- 📤 **Export Tools**: Generate shell commands for any profile

## 🎯 Real-World Examples

### Development Workflow Setup

#### Multi-Cloud Development
```bash
# AWS Profile
envman profile create aws -d "AWS development resources"
envman profile switch aws
envman add AWS_ACCESS_KEY_ID "AKIA..."
envman add AWS_SECRET_ACCESS_KEY "..." --encrypt
envman add AWS_DEFAULT_REGION "us-west-2"

# Azure Profile  
envman profile create azure -d "Azure development resources"
envman profile switch azure
envman add AZURE_CLIENT_ID "..."
envman add AZURE_CLIENT_SECRET "..." --encrypt
envman add AZURE_TENANT_ID "..."

# Quick switching between clouds
alias awsenv="envman profile switch aws && eval \"\$(envman export)\""
alias azureenv="envman profile switch azure && eval \"\$(envman export)\""
```

#### API Integration Projects
```bash
# OpenAI Project
envman profile create openai-project
envman add OPENAI_API_KEY "sk-..." --encrypt
envman add OPENAI_ORG_ID "org-..."
envman add MODEL_NAME "gpt-4"

# Stripe Integration
envman profile create stripe-integration  
envman add STRIPE_PUBLIC_KEY "pk_test_..."
envman add STRIPE_SECRET_KEY "sk_test_..." --encrypt
envman add STRIPE_WEBHOOK_SECRET "whsec_..." --encrypt
```

#### Environment-Specific Configurations
```bash
# Development Environment
envman profile create development
envman add NODE_ENV "development"
envman add DEBUG "true"
envman add LOG_LEVEL "debug"

# Staging Environment
envman profile create staging
envman add NODE_ENV "staging" 
envman add API_BASE_URL "https://api-staging.example.com"
envman add RATE_LIMIT "1000"

# Production Environment (with expiring tokens)
envman profile create production
envman add NODE_ENV "production"
envman add DEPLOY_TOKEN "temp_token" --expires 1h --encrypt
```

### Team Collaboration

#### Sharing Configuration Templates
```bash
# Export configuration template (values masked)
envman export > project-template.sh

# Team member imports and customizes
envman import < project-template.sh
envman add PERSONAL_API_KEY "their-key" --encrypt
```

#### Environment Synchronization
```bash
# Export non-sensitive configuration
envman export --skip-encrypted > shared-config.sh

# Import shared config and add personal secrets
source shared-config.sh
envman add PERSONAL_DB_PASSWORD "secret" --encrypt
```

## 🛠️ Shell Integration

### Bash/Zsh Setup
Add to your `.bashrc` or `.zshrc`:

```bash
# Environment Manager Aliases
alias envload="eval \"\$(envman export)\""
alias envstatus="envman status"

# Project-specific aliases
alias devenv="envman profile switch development && envload"
alias prodenv="envman profile switch production && envload"
alias stageenv="envman profile switch staging && envload"

# Quick profile switching function
switchenv() {
    envman profile switch "$1" && envload
    echo "Switched to $1 environment"
}
```

### Fish Shell Setup
Add to your `~/.config/fish/config.fish`:

```fish
# Environment Manager Functions
function envload
    eval (envman export -s fish)
end

function switchenv
    envman profile switch $argv[1]
    envload
    echo "Switched to $argv[1] environment"
end

# Aliases
alias envstatus="envman status"
alias devenv="switchenv development"
alias prodenv="switchenv production"
```

## 🏗️ File Structure

```
~/.env-manager/
├── profiles/                 # Profile-specific variable storage
│   ├── default.json         # Default profile variables  
│   ├── aws.json            # AWS profile variables
│   ├── azure.json          # Azure profile variables
│   └── openai.json         # OpenAI profile variables
├── profile-meta.json        # Profile metadata and descriptions
├── session.json            # Current session state and loaded variables
├── master-password.json    # Master password hash and metadata
└── settings.json          # Global settings and configuration
```

## 🔐 Security Features

### Encryption Options
- **Individual Encryption**: Each variable can have its own password
- **Master Password**: Bulk encrypt/decrypt entire profiles
- **Smart Masking**: Automatically masks sensitive variables in output
- **Secure Storage**: All encrypted data uses AES-256-GCM encryption

### Security Best Practices
- Variables stored locally (never transmitted)
- Strong password validation for encrypted variables
- Automatic masking of API keys, tokens, and passwords
- Optional master password for additional security layer
- Secure key derivation using PBKDF2 with 100,000 iterations

## 📡 API Reference

The web interface exposes a REST API for integration:

### Variables API
- `GET /api/variables` - List all variables
- `POST /api/variables` - Create variable
- `PUT /api/variables/:key` - Update variable
- `DELETE /api/variables/:key` - Delete variable
- `POST /api/variables/:key/encrypt` - Encrypt variable
- `POST /api/variables/:key/decrypt` - Decrypt variable

### Profiles API
- `GET /api/profiles` - List profiles
- `POST /api/profiles` - Create profile
- `POST /api/profiles/:name/switch` - Switch profile
- `DELETE /api/profiles/:name` - Delete profile

### Master Password API
- `GET /api/master/status` - Check master password status
- `POST /api/master/set` - Set master password
- `POST /api/master/change` - Change master password
- `POST /api/master/encrypt-all` - Bulk encrypt with master password

## 🤝 Contributing

We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.

### Development Setup
```bash
git clone https://github.com/kushal124/envman.git
cd env-manager
npm install
npm run dev
```

### Running Tests
```bash
npm test
npm run test:coverage
```

## 📝 License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## 🙋‍♂️ Support

- 📧 **Email**: [kushal124@example.com](mailto:kushal124@example.com)
- 🐛 **Issues**: [GitHub Issues](https://github.com/kushal124/envman/issues)
- 💬 **Discussions**: [GitHub Discussions](https://github.com/kushal124/envman/discussions)
- 📚 **Documentation**: [Full Documentation](https://kushal124.github.io/envman/)

## 🎉 Acknowledgments

- Built with ♥️ by [Kushal Khandelwal](https://github.com/kushal124)
- Inspired by the need for better developer environment management
- Thanks to all contributors and users for feedback and improvements

---

**Made with ❤️ for developers who manage multiple environments and API keys**

*Star ⭐ this repository if you find it helpful!*