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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@itgorillaz/configify

v4.0.2

Published

NestJS Config on Steroids

Readme

Description

configify is a NestJS configuration module that makes it easier to deal with configuration files and secrets.

Installation

$ npm install --save @itgorillaz/configify

Usage

To start using the configify module in your application import the module by calling the forRootAsync function:

@Module({
  imports: [ConfigifyModule.forRootAsync()],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}

Important Note: When working with strict mode enabled "strict": true(tsconfig.json) it's necessary to set the option strictPropertyInitialization to false since the module will initialize the configuration class properties during runtime after resolving the values of the environment variables.

By default, when bootstraping, the module will lookup for a .env, an application.yml and an application.json file at the root folder of the project:

my-web-app
| .env
| application.yml
| application.json

You can also provide the location of the configuration files by overriding the configuration options.

Mapping Configuration Classes

This module will lookup for every class decorated with @Configuration and it will make its instance globally available for the application.

Example of a .env file mapped to a class:

APPLICATION_CLIENT_ID=ABC
APPLICATION_CLIENT_TOKEN=TEST
@Configuration()
export class ApplicationClientConfig {
  @Value('APPLICATION_CLIENT_ID')
  appClientId: string;

  @Value('APPLICATION_CLIENT_TOKEN')
  appClientToken: string
}

Example of a .yml file mapped to a class:

database:
  host: localhost
  port: 3306
  username: test
  password: test
  metadata: |
    {
      "label": "staging"
    }
@Configuration()
export class DatabaseConfiguration {
  @Value('database.host')
  host: string;

  @Value('database.port', {
    parse: parseInt
  })
  port: number;

  @Value('database.metadata', {
    parse: JSON.parse
  })
  metadata: MetadataType;
}

You can map your configuration file to multiple configuration classes:

# database config
DATABASE_HOST=localhost
DATABASE_USER=test
DATABASE_PASSWORD=test

# okta config
OKTA_API_TOKEN=test
OKTA_CLIENT_ID=test
@Configuration()
export class DatabaseConfiguration {
  // database configuration attributes
}
@Configuration()
export class OktaConfiguration {
  // okta configuration attributes
}

Dependency Injection

This module makes all the configuration instances globally available to the application, to access it you just need to declare the configuration class as an argument in the class constructor:

export class AppService {
  private readonly LOGGER = new Logger(AppService.name);

  constructor(private readonly config: MyConfig) {
    this.LOGGER.log(JSON.stringify(config));
  }

}

Variables Expansion

You can make use of variable expansion in your configuration files:

MY_API_KEY=${MY_SECRET} // --> MY_API_KEY=TEST
ANY_OTHER_CONFIG=TEST
MY_SECRET=TEST
APP_CLIENT_ID=${NON_EXISTING_ENV:-DEFAULT_ID} // --> APP_CLIENT_ID=DEFAULT_ID

Defining Default Configuration Values

Other than defining default values with variables expansion, you can also define a default value to an attribute using the default option provided by the @Value() decorator:

@Configuration()
export class DatabaseConfiguration {
  @Value('DB_HOST', { default: 'localhost' })
  host: string;

  @Value('DB_PORT', {
    parse: parseInt,
    default: 3306
  })
  port: number;
}

Dealing with Secrets

Out of the box, this module can resolve secrets from:

  • AWS Secrets Manager and AWS Parameter Store
  • Azure Key Vault
  • Bitwarden Secrets Manager
  • Google Cloud Secret Manager
  • Custom Remote Configuration Resolver(your own implementation)

Check the examples and their documentation to learn how to use them.

Parsing Configuration Values

Parsing a configuration value can be easily done by using a parse callback function available as argument of the @Value() decorator:

db-json-config: |
  {
    "host": "localhost",
    "user": "test",
    "password": "test"
  }
export interface MyDBConfig {
  host: string;
  user: string;
  password: string;
}

@Configuration()
export class SuperSecretConfiguration {
  @Value('db-json-config', {
    parse: JSON.parse
  })
  myDbConfig: MyDBConfig;
}

Validating Configuration Classes

Depending on how critical a configuration is, you may want to validate it before starting the application, for that you can use class-validator to make sure your configuration is loaded correctly:

@Configuration()
export class MyConfiguration {
  @IsEmail()
  @Value('SENDER_EMAIL')
  senderEmail: string;

  @IsNotEmpty()
  @Value('my-api-token')
  myApiToken: string;
}

Overwrite Default Options

You can overwrite default module options by providing an object as argument to the forRootAsync() method:

/**
* Ignores any config file.
* The default value is false;
*/
ignoreConfigFile?: boolean;

/**
* Ignores environment variables
* The default value is false;
*/
ignoreEnvVars?: boolean;

/**
* The path of the configuration files
*/
configFilePath?: string | string[];

/**
* Expands variables
* The default value is true
*/
expandConfig?: boolean;

/**
 * The secrets resolvers strategies
 */
secretsResolverStrategies?: ConfigurationResolver[];

License

This code is licensed under the MIT License.

All files located in the node_modules and external directories are externally maintained libraries used by this software which have their own licenses; we recommend you read them, as their terms may differ from the terms in the MIT License.