npm package: @raphaellcs/env-manager
Description: Manage environment variables with ease
Author: Dream Heart
Latest version: 1.0.0

# @raphaellcs/env-manager

A simple and powerful tool for managing environment variables with ease.

## Features

- 📋 **List** all environment variables
- 🔍 **Get** specific variables
- ✏️ **Set** new variables
- 🗑️ **Remove** variables
- 📄 **Validate** environment file format
- 📋 **Copy** variables between files
- 🔒 **Mask** sensitive values by default

## Installation

```bash
# Use with npx (no installation needed)
npx @raphaellcs/env-manager --help

# Or install globally
npm install -g @raphaellcs/env-manager
```

## Usage

### List Environment Variables

```bash
# List all variables from .env file
npx @raphaellcs/env-manager list

# List from custom file
npx @raphaellcs/env-manager list --file config.env

# Include system environment variables
npx @raphaellcs/env-manager list --all
```

### Get a Specific Variable

```bash
# Get a variable
npx @raphaellcs/env-manager get DB_HOST

# Get from custom file
npx @raphaellcs/env-manager get API_KEY --file .env.production

# Show raw value without masking
npx @raphaellcs/env-manager get PASSWORD --raw
```

### Set a Variable

```bash
# Set a new variable
npx @raphaellcs/env-manager set DB_HOST localhost

# Set in custom file
npx @raphaellcs/env-manager set NODE_ENV production --file .env.production
```

### Remove a Variable

```bash
# Remove a variable
npx @raphaellcs/env-manager unset DB_HOST

# Remove from custom file
npx @raphaellcs/env-manager unset API_KEY --file .env.test
```

### Initialize .env File

```bash
# Create a new .env file with template
npx @raphaellcs/env-manager init

# Create with custom name
npx @raphaellcs/env-manager init --file .env.example
```

### Copy Variables Between Files

```bash
# Copy from .env.example to .env
npx @raphaellcs/env-manager copy .env.example .env

# Copy and overwrite existing variables
npx @raphaellcs/env-manager copy .env.example .env --overwrite
```

### Validate Environment File

```bash
# Validate .env file
npx @raphaellcs/env-manager validate

# Validate custom file
npx @raphaellcs/env-manager validate --file .env.production
```

## Examples

### Example 1: List All Variables

```bash
$ npx @raphaellcs/env-manager list

📋 Environment Variables (.env):

  DB_HOST = lo****st
  DB_PORT = 54****
  DB_NAME = my**
  DB_USER = po*******e
  DB_PASSWORD = pa******re

$ npx @raphaellcs/env-manager list --all

📋 Environment Variables (.env):

  DB_HOST = lo****st
  DB_PORT = 54****

System Environment Variables:

  NODE_ENV = de********ent
  HOME = /h**e/l
```

### Example 2: Create and Set Variables

```bash
$ npx @raphaellcs/env-manager init
✓ Created .env
Edit the file and add your environment variables.

$ npx @raphaellcs/env-manager set DB_HOST localhost
✓ Set DB_HOST successfully

$ npx @raphaellcs/env-manager set API_KEY secret123
✓ Set API_KEY successfully
```

### Example 3: Get Variables

```bash
$ npx @raphaellcs/env-manager get DB_HOST
localhost

$ npx @raphaellcs/env-manager get API_KEY
se****23

$ npx @raphaellcs/env-manager get API_KEY --raw
secret123
```

### Example 4: Validate File

```bash
$ npx @raphaellcs/env-manager validate
✔ File is valid

$ npx @raphaellcs/env-manager validate
  Line 5: Missing '=' separator
  Line 8: Spaces in key name
⚠ File is valid with 1 error(s) and 1 warning(s)
```

### Example 5: Copy Variables

```bash
$ npx @raphaellcs/env-manager copy .env.example .env
✓ Copied 8 variable(s) to .env

$ npx @raphaellcs/env-manager copy .env.example .env --overwrite
✓ Copied 12 variable(s) to .env
```

## Best Practices

### 1. Never Commit .env Files

Add `.env` to your `.gitignore`:

```gitignore
.env
.env.local
.env.*.local
```

### 2. Use .env.example

Create a template file:

```bash
npx @raphaellcs/env-manager init --file .env.example
```

Commit this file so others know which variables are needed.

### 3. Use Different Files for Different Environments

```bash
# Development
.env

# Staging
.env.staging

# Production
.env.production
```

### 4. Reference Variables in Code

```javascript
// In Node.js
require('dotenv').config();

const dbHost = process.env.DB_HOST;
const apiKey = process.env.API_KEY;
```

## Security Tips

- ❌ Never commit `.env` files
- ✅ Use `.env.example` as a template
- 🔒 Rotate sensitive keys regularly
- 📋 Use different files for different environments
- 🚫 Don't include `.env` in backups
- 🔑 Use strong passwords and keys

## Common Use Cases

### Development Setup

```bash
# 1. Create .env.example
npx @raphaellcs/env-manager init --file .env.example

# 2. Team member creates their own .env
npx @raphaellcs/env-manager init

# 3. Set variables
npx @raphaellcs/env-manager set DB_HOST localhost
npx @raphaellcs/env-manager set NODE_ENV development
```

### Deployment

```bash
# 1. Copy from example to production
npx @raphaellcs/env-manager copy .env.example .env.production

# 2. Set production values
npx @raphaellcs/env-manager set NODE_ENV production --file .env.production
npx @raphaellcs/env-manager set API_KEY production_key --file .env.production

# 3. Validate before deploy
npx @raphaellcs/env-manager validate --file .env.production
```

### Configuration Management

```bash
# Check current configuration
npx @raphaellcs/env-manager list

# Verify specific values
npx @raphaellcs/env-manager get DB_HOST

# Update configuration
npx @raphaellcs/env-manager set DB_PORT 5432

# Remove unused variables
npx @raphaellcs/env-manager unset DEBUG
```

## Contributing

Contributions are welcome! Feel free to open an issue or submit a pull request.

## License

MIT

## Author

Dream Heart 🌙

## Links

- [npm](https://www.npmjs.com/package/@raphaellcs/env-manager)
- [GitHub](https://github.com/RaphaelLcs-financial/env-manager)