
Security News
The Hidden Blast Radius of the Axios Compromise
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.
@redhare/config
Advanced tools
# 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
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.
yarn install @infra-node-kit/config
It will share the same API with @nestjs/config. The API of @nestjs/config can be found at https://docs.nestjs.com/techniques/configuration
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 {}
import { Module } from '@nestjs/common'
import { ConfigModule } from '@infra-node-kit/config'
@Module({
imports: [ConfigModule.forRoot({
isGlobal: true,
loadEnvConfig: {
enable: true,
}
})],
})
export class AppModule {}
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 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
},
}
export interface IConfigSpaceOption {
namespace: string
filePath: string
fileType?: CONFIG_FILE_TYPE
fileEncoding?: BufferEncoding
}
export interface IConfigModuleOptions extends NestjsConfigModuleOptions {
configMap?: IConfigSpaceOption[]
}
FAQs
# 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
We found that @redhare/config demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.

Research
A supply chain attack on Axios introduced a malicious dependency, plain-crypto-js@4.2.1, published minutes earlier and absent from the project’s GitHub releases.

Research
Malicious versions of the Telnyx Python SDK on PyPI delivered credential-stealing malware via a multi-stage supply chain attack.