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

@geisonjr/envfy

v1.0.1

Published

A simple package to manage environment variables

Downloads

14

Readme

Easy to use, fast and lightweight library for Node.js.

[!WARNING] This project is under development and is not yet ready for use.

🌱 Overview

The .env files are used to define environment variables for the project. The following files are used to manage configurations for different environments, such as development, testing, and production.

This structure enables a clear and organized approach to managing configurations, making it easier to customize settings for specific environments while maintaining a consistent setup for shared configurations

✨ Features

  • [x] process.env variables
  • [x] .env and .env.local files
  • [x] .env.${NODE_ENV} and .env.${NODE_ENV}.local files
  • [x] Default, required and strict values
  • [x] Get value as array, boolean, number, string
  • [ ] Get value as date, object, url

🚀 Tecnologies

The following tools were used in the construction of the project:

📦 Install

Use the package manager npm, yarn.

npm install @geisonjr/envfy
yarn add @geisonjr/envfy

📋 Environment Files

[!TIP] Both .env and .env.local files are loaded across all environments, providing a foundation for common configurations.

[!IMPORTANT] These base configuration files reside in the root of the project.

[!IMPORTANT] The prority of the environment variables is as follows:

  1. process.env - default environment variables from the OS
  2. .env - overrides process.env
  3. .env.local - overrides .env
  4. .env.${NODE_ENV} - overrides .env.local
  5. .env.${NODE_ENV}.local - overrides .env.${NODE_ENV}

Base Files

.env: Default environment variables.

Environment-Specific Files

The .env* files are selected based on the NODE_ENV environment variable, allowing tailored configurations for different deployment scenarios.

.env.${NODE_ENV}: Environment-specific settings.

Example

In the following example, the .env.development file is used to define environment variables for the development environment when the NODE_ENV environment variable is set to development.

NODE_ENV=development
# .env.development
ENV_VAR_STRING=development-value
ENV_VAR_NUMBER=456

Local Overrides

The .env*.local files are used to override configurations for local development, providing a way to customize settings without affecting the shared configurations.

[!CAUTION] The .env*.local files are not committed to the version control system, as they are intended for local overrides. This practice ensures that the local environment settings do not interfere with the shared configurations.

🏗️ Usage

Use environment variables directly from process.env

Create a .env file in the root of your project and add your environment variables.

ENV_VAR_STRING=my-value // Can also use double quotes
ENV_VAR_NUMBER=123 // Can also use floating point numbers
ENV_VAR_BOOLEAN=true // "true", "yes", "y", "1", "on" are considered true

[!TIP] The following types are supported:

  • array - Can also use double quotes
    • 1;2;3 or "1;2;3"
  • boolean - Can also use double quotes, Case insensitive
    • Truthy: true, yes, y, 1, on.
    • Falsy: false, no, n, 0, off.
  • number - Can also use double quotes
    • 123
    • 123,456.789
  • string - Can also use double quotes
    • my-value or "my-value"

Import the package in your code and use the environment variables.

import '@geisonjr/envfy/config'

// Environment variables are now available in process.env
process.env.ENV_VAR_STRING // 'my-value'
process.env.ENV_VAR_NUMBER // '123'
process.env.ENV_VAR_BOOLEAN // 'true'

How use the Env class

import * as envfy from '@geisonjr/envfy'

// Get value as boolean
envfy.boolean('ENV_VAR_BOOLEAN') // true
// Get value as number
envfy.number('ENV_VAR_NUMBER') // 123
// Get value as string
envfy.string('ENV_VAR_STRING') // 'my-value'

How use default values

import * as envfy from '@geisonjr/envfy'

// Get value as boolean with default value
envfy.boolean('ENV_VAR_NOT_EXISTS', true) // true
// Get value as number with default value
envfy.number('ENV_VAR_NOT_EXISTS', 123.45) // 123.45
// Get value as string with default value
envfy.string('ENV_VAR_NOT_EXISTS', 'default-value') // 'default-value'

📋 License

This project is under the MIT License