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

@yaml-js/envyaml

v0.2.3

Published

YAML-JS EnvYaml is a modern replacement for traditional .env files, using YAML syntax.

Downloads

681

Readme

YAML-JS EnvYaml

NPM License GitHub Actions Workflow Status Sonar Quality Gate Sonar Tech Debt Sonar Coverage Known Vulnerabilities GitHub Issues or Pull Requests

YAML-JS EnvYaml is a modern replacement for traditional .env files, using YAML syntax. This tool provides a seamless way to manage environment configurations with enhanced readability and structure, making it ideal for modern JavaScript and TypeScript projects.

Features

  • Complex Nested Configurations: Supports deeply nested structures, allowing for more organized and hierarchical configuration files.
  • Easy Integration: Simple and straightforward integration with existing JavaScript/TypeScript projects.
  • Environment Variables & Overrides: Built-in support for using environment variables and overriding configurations based on the environment (e.g., development, production).

Installation

To install YAML-JS EnvYaml in your project, run:

npm install @yaml-js/envyaml

or with yarn:

yarn add @yaml-js/envyaml

Usage

Basic Example

Create a .env.yaml file:

settings:
  app:
    name: MyApp
    version: 1.0.0
    port: 3000
  database:
    host: localhost
    port: 5432

Also create coorespondent files for your developement environment, and name it .env.dev.yaml

settings:
  app:
    port: 3001
  database:
    host: https://dev.db.org

and one other for the production environment, and name it .env.prod.yaml

settings:
  app:
    port: 443
  database:
    host: https://prod.db.org

Load and use the configuration in your JavaScript/TypeScript project:

import config from '@yaml-js/envyaml';

config('.env.yaml', process.env.NODE_ENV || 'development');

console.log(`App running on port: ${process.env.app.port}`);
console.log(`Database host: ${process.env.database.host}`);

Environment Variable Overrides

You can override specific values using environment variables:

settings:
  database:
    host: ${DB_HOST}

This allows you to inject environment-specific values without changing the configuration files.

API

config(filePath: string = '.env.yaml', environment: string = process.env.NODE_ENV): Config

  • filePath: The path to the YAML configuration file.
  • environment: The environment to load (e.g., development, production).

Initializes process.env with the configuration for the specified environment.

Example

import config from '@yaml-js/envyaml';
config();

Advantages over .env Files

  • Readability: YAML’s structured format is easier to read and maintain than flat .env files.
  • Hierarchy: Organize your configurations into nested structures.
  • Flexibility: Supports multiple environments in a single file.

Contributing

Contributions are welcome! Please follow the steps below:

1.	Fork the repository.
2.	Create a new branch (git checkout -b feature/my-feature).
3.	Make your changes and commit them (git commit -m 'Add my feature').
4.	Push to the branch (git push origin feature/my-feature).
5.	Open a Pull Request.

License

This project is licensed under the MIT License. See the LICENSE file for details.