New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

envpro-cli

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

envpro-cli

CLI tool for managing environment files with TypeScript support

latest
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

envpro 🌱

A powerful environment management tool for Node.js applications. Manage, encrypt, and switch between different environment configurations with ease.

Features ✨

  • 🔐 Secure Encryption: Encrypt your environment files with AES-256-GCM
  • 🔄 Environment Switching: Easily switch between different environments
  • 🔑 Key Management: Automatic key generation and storage
  • 📦 Backup System: Automatic backups with easy restoration
  • 🛡️ Security: Secure key storage and encrypted files
  • 🎯 TypeScript Support: Built with TypeScript for better development experience
  • 🔍 Environment Validation: Validate environment variables against a schema
  • 🔄 Automatic Loading: Load environment variables without dotenv dependency

Installation 📦

# Install globally
npm install -g envpro

# Or install as a dev dependency
npm install --save-dev envpro

Quick Start 🚀

  • Initialize envpro in your project:

    envpro init
    
  • Create your first environment:

    envpro new development
    
  • Add your environment variables:

    # Edit .env.development
    DATABASE_URL=postgres://user:pass@localhost:5432/dev_db
    API_KEY=your_api_key
    
  • Encrypt your environment:

    envpro encrypt development
    
  • Use the environment in your code:

    import { useEnv, getEnvVar } from 'envpro/utils/env-loader';
    
    // Load environment variables
    await useEnv({
        environment: 'development'
    });
    
    // Access variables
    const dbUrl = getEnvVar('DATABASE_URL');
    

Sample Project Usage 🏗️

1. Project Setup

# Initialize project
mkdir my-app
cd my-app
npm init -y
npm install --save-dev envpro typescript @types/node

2. Configure TypeScript

// tsconfig.json
{
  "compilerOptions": {
    "target": "ES2020",
    "module": "commonjs",
    "outDir": "./dist",
    "rootDir": "./src",
    "strict": true,
    "esModuleInterop": true
  }
}

3. Initialize envpro

envpro init
envpro new development
envpro new production

4. Add Environment Variables

# .env.development
DATABASE_URL=postgres://user:pass@localhost:5432/dev_db
API_KEY=dev_api_key
PORT=3000
NODE_ENV=development

# .env.production
DATABASE_URL=postgres://user:pass@prod-db:5432/prod_db
API_KEY=prod_api_key
PORT=80
NODE_ENV=production

5. Encrypt Environments

envpro encrypt development
envpro encrypt production

6. Create Application Code

// src/index.ts
import { useEnv, getEnvVar } from 'envpro/utils/env-loader';

async function main() {
    // Load environment variables
    await useEnv({
        environment: process.env.NODE_ENV || 'development'
    });

    // Access variables
    const dbUrl = getEnvVar('DATABASE_URL');
    const port = getEnvVar('PORT') || '3000';
    const apiKey = getEnvVar('API_KEY');

    console.log('Database URL:', dbUrl);
    console.log('Port:', port);
    console.log('API Key:', apiKey ? '***' : 'Not set');
}

main().catch(console.error);

7. Build and Run

# Build
npm run build

# Run in development
NODE_ENV=development node dist/index.js

# Run in production
NODE_ENV=production node dist/index.js

Advanced Usage Examples 🚀

1. Environment Validation

import { useEnv, getEnvVar } from 'envpro/utils/env-loader';

interface EnvSchema {
    DATABASE_URL: string;
    API_KEY: string;
    PORT?: string;
}

async function validateEnv(): Promise<EnvSchema> {
    await useEnv();
    
    const requiredVars = ['DATABASE_URL', 'API_KEY'];
    for (const key of requiredVars) {
        if (!getEnvVar(key)) {
            throw new Error(`Missing required environment variable: ${key}`);
        }
    }

    return {
        DATABASE_URL: getEnvVar('DATABASE_URL')!,
        API_KEY: getEnvVar('API_KEY')!,
        PORT: getEnvVar('PORT')
    };
}

2. Multiple Environment Support

import { useEnv, getEnvVar } from 'envpro/utils/env-loader';

class Config {
    private static instance: Config;
    private env: string;

    private constructor() {
        this.env = process.env.NODE_ENV || 'development';
    }

    static async getInstance(): Promise<Config> {
        if (!Config.instance) {
            Config.instance = new Config();
            await useEnv({
                environment: Config.instance.env,
                override: true
            });
        }
        return Config.instance;
    }

    getDatabaseUrl(): string {
        return getEnvVar('DATABASE_URL')!;
    }

    getApiKey(): string {
        return getEnvVar('API_KEY')!;
    }

    getPort(): number {
        return parseInt(getEnvVar('PORT') || '3000', 10);
    }
}

// Usage
async function main() {
    const config = await Config.getInstance();
    console.log('Database URL:', config.getDatabaseUrl());
    console.log('Port:', config.getPort());
}

3. Environment Switching in Tests

import { useEnv } from 'envpro/utils/env-loader';

describe('My Test Suite', () => {
    beforeAll(async () => {
        await useEnv({
            environment: 'test',
            override: true
        });
    });

    it('should use test environment variables', () => {
        expect(process.env.NODE_ENV).toBe('test');
        // ... rest of your test
    });
});

Security Best Practices 🔒

  • Key Management:

    • Keys are stored in .envpro/keys/
    • Each environment has its own key
    • Keys are automatically generated and managed
  • File Security:

    • Never commit unencrypted .env files
    • Keep .envpro/keys/ in a secure location
    • Use different keys for different environments
  • Backup Strategy:

    • Regular backups using envpro backup
    • Store backups securely
    • Use the restore system for recovery

Troubleshooting 🛠️

Common Issues

  • Key Not Found

    ❌ No encryption key found!
    💡 Please ensure:
      1. The key exists in .envpro/keys/
      2. Or set it as an environment variable: ENCRYPTION_KEY=your_key
    

    Solution: Run envpro encrypt <environment> to generate a new key.

  • File Not Found

    ❌ Environment file not found: .env.production
    

    Solution: Create the environment first using envpro new production.

  • Decryption Failed

    ❌ Decryption failed: Invalid encryption key
    

    Solution: Ensure you're using the correct key for the environment.

Contributing 🤝

  • Fork the repository
  • Create your feature branch
  • Commit your changes
  • Push to the branch
  • Create a Pull Request

License 📄

MIT License - feel free to use this tool in your projects!

Support 💖

If you find this tool helpful, please consider giving it a ⭐️ on GitHub!

Made with ❤️ by [Avijit Sen]

FAQs

Package last updated on 20 Apr 2025

Did you know?

Socket

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.

Install

Related posts