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

typed-environment-loader

v0.3.0

Published

typed-environment-loader is a lightweight utility for loading environment variables in a typed manner, ensuring type safety and consistency in your Node.js applications.

Downloads

10

Readme

typed-environment-loader

License: MIT

NPM

typed-environment-loader is a lightweight utility for loading environment variables in a typed manner, ensuring type safety and consistency in your Node.js applications.

Installation

You can install typed-environment-loader via npm:

npm install typed-environment-loader

Usage

import * as dotenv from 'dotenv';
import { Configuration, EnvironmentLoader, ParsedConfig } from 'typed-environment-loader';

const config: Configuration = {
 port: { type: 'number', default: 3000, required: true, name: 'PORT' },
 nodeEnv: {
  type: 'enum',
  values: ['production', 'development', 'test'],
  default: 'development',
  required: true,
  name: 'NODE_ENV'
 },
 postgres: {
  host: { type: 'string', default: 'localhost', required: true, name: 'POSTGRES_HOST' },
  password: { type: 'string', required: true, name: 'POSTGRES_PASSWORD' },
  port: { type: 'number', default: 5432, required: true, name: 'POSTGRES_PORT' }
 },
 cors: {
  enabled: { type: 'boolean', default: true, required: true, name: 'CORS_ENABLED' },
  origins: { type: 'array', items: { type: 'string' }, default: ['*'], required: true, name: 'CORS_ORIGINS' }
 },
 matrix: {
  type: 'array',
  items: { type: 'array', items: { type: 'number' } },
  required: false,
  name: 'MATRIX'
 }
};

interface Config extends ParsedConfig {
 port: number;
 nodeEnv: 'production' | 'development' | 'test';
 postgres: {
  host: string;
  password: string;
  port: number;
 };
 cors: {
  enabled: boolean;
  origins: Array<string>;
 };
 matrix: Array<Array<number>>;
}
const loadedEnv = dotenv.config({});
if (loadedEnv.error) {
    throw new Error(
    `Error loading environment variables from.env file it must be located in the root of the project.`
    );
}
const loader = new EnvironmentLoader<Config>(config);
const configObject = loader.loadFromFile().load();

console.log(configObject);

Why typed-environment-loader?

typed-environment-loader provides a simple and intuitive way to load environment variables in your Node.js applications while ensuring type safety and consistency. Here's why you should choose it:

  • Declarative Style: typed-environment-loader uses a declarative style for defining environment variable configurations. This allows you to specify the structure of your environment variables in a clear and concise manner, making it easy to understand and maintain.

  • Type Safety: With typed-environment-loader, you can specify the types of your environment variables, ensuring that your application receives the correct data types. This helps prevent runtime errors and enhances code reliability.

  • Consistency: By defining your environment variable structure in one place, you maintain consistency across your application's configuration. This reduces the risk of configuration errors and makes it easier to manage and scale your application.

  • Ease of Use: typed-environment-loader offers a clean and straightforward API for loading environment variables, making it easy to integrate into your projects. Whether you're working on a small project or a large-scale application, typed-environment-loader provides a hassle-free solution for managing your environment configurations.

Issues

We welcome any contributions or feedback! If you encounter any bugs, have feature requests, or want to ask questions, please don't hesitate to create an issue. We also have specific issue templates to help guide you in providing the necessary information.

Issue Templates

For your convenience, we have provided issue templates to cover common types of contributions. You can find them in the .github/ISSUE_TEMPLATE/ directory:

  • Bug Report: Use this template if you've encountered a bug or unexpected behavior in the library.
  • Feature Request: Use this template to propose a new feature or enhancement.
  • Question / Help Wanted: Use this template if you have questions or need help with using the library.

Please make sure to fill out all the sections in the template relevant to your issue. This will help us understand your request better and address it promptly.

Contributing

If you'd like to contribute code, please refer to the Contributing Guidelines for instructions on how to contribute. We appreciate your help in improving typed-environment-loader!

License

typed-environment-loader is open-source software licensed under the MIT license.