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

@redhare/config

v0.0.2

Published

# Background Currently configuration module code is hardcoded into the template code which will make future update or bug fix infeasible. The configuration module code should be extracted into an independent nestjs module. In this way developer can not o

Downloads

3

Readme

@infra-node-kit/config

Background

Currently configuration module code is hardcoded into the template code which will make future update or bug fix infeasible. The configuration module code should be extracted into an independent nestjs module. In this way developer can not only update the corresponding package when new features are released, but also have an option to choose whether they want to use our module in their project.

Features

  • Compatible to nestjs official configuration module.
  • Watch the configuration file and hot-reload it when the file content change(Except ts config files).
  • Can depend the environment variable value and user set directory, merge the config result from diffrent file.

How to use

Install

yarn install @infra-node-kit/config

API

It will share the same API with @nestjs/config. The API of @nestjs/config can be found at https://docs.nestjs.com/techniques/configuration

Basic use

It is recommended to refer to the usage example and path of the unit test part of the source code:

/packages/config/src/__test__/testModule
import { Module } from '@nestjs/common'
import { join } from 'path'
import { AppController } from './app.controller'
import { AppService } from './app.service'
// import { ConfigModule } from '@nestjs/config'
// change the line above to the line below
import { ConfigModule } from '@infra-node-kit/config'
import { PfbModule } from './pfb/pfb.module'

const configMap = [
  {
    namespace: 'ns1',
    filePath: join(process.cwd(), 'config', 'ymlConfig.yaml')
  },
  {
    namespace: 'ns2',
    filePath: join(process.cwd(), 'config', 'jsonConfig.json')
  },
  {
    namespace: 'ns3',
    filePath: join(process.cwd(), 'config', 'tsConfig.ts')
  }
]
@Module({
  imports: [PfbModule, ConfigModule.forRoot({ configMap, isGlobal: true })],
  controllers: [AppController],
  providers: [AppService]
})
export class AppModule {}

loadEnvConfig

Usage

import { Module } from '@nestjs/common'
import { ConfigModule } from '@infra-node-kit/config'
@Module({
  imports: [ConfigModule.forRoot({
    isGlobal: true,
    loadEnvConfig: {
      enable: true,
    }
    })],

})
export class AppModule {}

params

loadEnvConfig is a param in ConfigModule.forRoot, It is an another way to load config file beside the configMap. The structure is below:

export interface IEnvConfig {
  enable?: boolean
  dir?: string
  env?: string
}

enable is to enable the load function. dir is an absolute directory which decide the directory of config files. default value is join(process.cwd(), 'dist/configs') env is a variable which sign the environment, default value is join(process.cwd(), 'dist/configs')

default dir example:

- src
- - - configs
- - - - config.default.ts
- - - - config.local.ts
- - - - config.test.ts
- - - - config.live.ts

Nest project default will compile src directory to dist directory, so when we set the dir params,we need pay attention to that. Finally path is dist not src.

Naming rule and Merge rule

Naming rules of env config filename is config.${env} and all env default filename is config.default. The final result is the merge of config.default and config.${env}. Object item will recursive merge.

The merge example config.default.ts

export default {
  env: 'default',
  envObject: {
    env: 'default',
    save: true,
  },
}

config.live.ts

export default {
  env: 'live',
  envObject: {
    env: 'live',
  },
}

if the env value is live, then the config result is:

{
  env: 'live',
  envObject: {
    env: 'live',
    save: true
  },
}

Types

export interface IConfigSpaceOption {
  namespace: string
  filePath: string
  fileType?: CONFIG_FILE_TYPE
  fileEncoding?: BufferEncoding
}

export interface IConfigModuleOptions extends NestjsConfigModuleOptions {
  configMap?: IConfigSpaceOption[]
}