npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

enviroconfig

v0.0.2

Published

A flexible and easy-to-use Node.js package designed to manage environment configurations.

Downloads

2

Readme

EnviroConfig

🚀 Description

EnviroConfig is a flexible and easy-to-use Node.js package designed to manage environment configurations. It addresses the common issue of handling multiple sets of environment variables for different environments, such as development, testing, and production. By using EnviroConfig, developers can easily switch between these environments, apply default values, validate configurations against schemas, and set custom paths for environment files. This package ensures that applications are configured correctly and consistently across various environments, reducing errors and simplifying the setup process.

👨‍💻 How to Install

To install EnviroConfig, run the following command:

npm install enviroconfig

👨‍💻 How to Use

Using EnviroConfig in a Node.js Project

  1. Create Environment Files

    Create .env.development, .env.testing, and .env.production files in your project root:

    # .env.development
    DB_HOST=localhost
    DB_PORT=5432
    API_KEY=dev123
    # .env.testing
    DB_HOST=localhost
    DB_PORT=5433
    API_KEY=test123
    # .env.production
    DB_HOST=prod.db.server
    DB_PORT=5432
    API_KEY=prod123
  2. Initialize EnviroConfig

    Create a config.js file and use EnviroConfig:

    const EnviroConfig = require('enviro-config');
    const Joi = require('joi');
    
    const schema = Joi.object({
    DB_HOST: Joi.string().required(),
    DB_PORT: Joi.number().default(5432),
    API_KEY: Joi.string().required()
    });
    
    const config = new EnviroConfig({
    env: 'development',
    schema: schema,
    defaults: { DB_PORT: 5432 },
    configPath: __dirname
    });
    
    console.log('DB_HOST:', process.env.DB_HOST);
    console.log('DB_PORT:', process.env.DB_PORT);
  3. Switch Environment

    config.switchEnv('production');
    console.log('Production DB_HOST:', process.env.DB_HOST);

Using EnviroConfig in a TypeScript Project

  1. Create Environment Files Create .env.development, .env.testing, and .env.production files as shown in the Node.js example.
  2. Initialize EnviroConfig Create a config.ts file and use EnviroConfig:
    import EnviroConfig from 'enviro-config';
    import Joi from 'joi';
    
    const schema = Joi.object({
    DB_HOST: Joi.string().required(),
    DB_PORT: Joi.number().default(5432),
    API_KEY: Joi.string().required()
    });
    
    const config = new EnviroConfig({
    env: 'development',
    schema: schema,
    defaults: { DB_PORT: 5432 },
    configPath: __dirname
    });
    
    console.log('DB_HOST:', process.env.DB_HOST);
    console.log('DB_PORT:', process.env.DB_PORT);
    
  3. Switch Environment
    config.switchEnv('production');
    console.log('Production DB_HOST:', process.env.DB_HOST);

✨ Features

  • Default Values: Apply default values for missing environment variables.interaction.
  • Schema Validation: Validate environment variables against a schema using Joi.
  • Custom Configuration Paths: Set custom paths for environment files.
  • Switch Environments: Easily switch between different environment configurations.

Applying Default Values

const config = new EnviroConfig({
  env: 'development',
  defaults: { DB_PORT: 5432 }
});

Schema Validation

const schema = Joi.object({
  DB_HOST: Joi.string().required(),
  DB_PORT: Joi.number().default(5432),
  API_KEY: Joi.string().required()
});

const config = new EnviroConfig({
  env: 'development',
  schema: schema
});

Custom Configuration Paths

const config = new EnviroConfig({
  env: 'development',
  configPath: '/custom/path/to/config'
});

👋 From Dev

EnviroConfig simplifies the management of environment variables in Node.js applications. By providing features such as default values, schema validation, and easy switching between environments, it helps ensure that your application is consistently configured across different stages of development. This reduces configuration errors and improves overall development efficiency.

🪪 License

[MIT]