
Research
SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains
An emerging npm supply chain attack that infects repos, steals CI secrets, and targets developer AI toolchains for further compromise.
@codemask-labs/node-config
Advanced tools
A utility library designed to simplify configuration management in TypeScript and Node.js applications. This library includes powerful decorators, validation features, and utils to effortlessly integrate and validate application configurations.
getConfig function ensures type safety by mapping environment variables directly to configuration class properties.class-validator@IsString, @IsEnum, @IsInt, and @IsBoolean to enforce rules on configuration values.class-transformer@Transform.Injectables in Nestjs modulesyarn add @codemask-labs/node-config class-validator class-transformer
npm install @codemask-labs/node-config class-validator class-transformer
declare function getConfig(configClass: ClassType): ConfigInstance
Retrieves and validates an instance of the configuration class.
@Config and validation decorators applied.declare function getConfigValue<T extends ClassType, U>(configClass: T, getter: (config: T) => U): U
Retrieves and validates an instance of the configuration class, and passed through a getter to return a value.
@Config and validation decorators applied.declare function Env(propertyName: string): MethodDecorator
Maps process environment to class property by name, useful when you need to validate or transform environment variable and map it to other casing.
process.env key to a valueUse decorators to define and validate configuration properties.
import { Transform } from 'class-transformer';
import { IsBoolean, IsEnum, IsInt, IsString, MaxLength } from 'class-validator';
import { Config } from '@codemask-labs/node-config';
import { TypeormConnection } from 'example/enums';
@Config()
export class TypeormConfig {
@IsEnum(TypeormConnection)
readonly TYPEORM_CONNECTION: TypeormConnection;
@IsString()
readonly TYPEORM_HOST: string;
@IsInt()
readonly TYPEORM_PORT: number;
@IsString()
readonly TYPEORM_DATABASE: string;
@IsString()
@MaxLength(100)
readonly TYPEORM_USERNAME: string;
@IsString()
readonly TYPEORM_PASSWORD: string;
@IsBoolean()
readonly TYPEORM_LOGGING: boolean;
@IsBoolean()
@Transform(({ value }) => value === 'true')
readonly TYPEORM_DEBUG: boolean;
}
Use the getConfig function to access and validate the configuration class.
import { getConfig } from '@codemask-labs/node-config';
import { TypeormConfig } from 'example/config';
const config = getConfig(TypeormConfig);
console.log(config.TYPEORM_HOST); // Outputs the validated host value
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { getConfig } from '@codemask-labs/node-config';
import { TypeormConfig } from 'example/config';
@Module({
imports: [
TypeOrmModule.forRootAsync({
useFactory: () => {
const {
TYPEORM_CONNECTION,
TYPEORM_HOST,
TYPEORM_PORT,
TYPEORM_USERNAME,
TYPEORM_PASSWORD,
TYPEORM_DATABASE,
TYPEORM_LOGGING,
} = getConfig(TypeormConfig);
return {
type: TYPEORM_CONNECTION,
host: TYPEORM_HOST,
port: TYPEORM_PORT,
username: TYPEORM_USERNAME,
password: TYPEORM_PASSWORD,
database: TYPEORM_DATABASE,
entities: Object.values({}),
migrations: Object.values({}),
synchronize: false,
migrationsRun: true,
autoLoadEntities: true,
logging: TYPEORM_LOGGING ? 'all' : undefined,
};
},
}),
],
})
export class UsersModule {}
import { NodeEnv } from 'example/enums';
export class NodeConfig {
@IsEnum(NodeEnv)
@Env('NODE_ENV') // reads it from `process.env`, and maps it to your class property `environment`
readonly environment: NodeEnv;
}
import { NodeConfig } from 'example/config';
export class TypeormConfig {
constructor(readonly nodeConfig: NodeConfig) {}
}
import { TypeormConfig } from 'example/config';
const config = getConfig(TypeormConfig); // Transforms and validates `NodeConfig` as dependency, then transforms and validates `TypeormConfig`, returns instance.
console.log(config.nodeConfig.environment); // Outputs the validated and transformed value of `NODE_ENV`
This project is licensed under the MIT License.
FAQs
Node Config Module
We found that @codemask-labs/node-config demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 5 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.

Research
An emerging npm supply chain attack that infects repos, steals CI secrets, and targets developer AI toolchains for further compromise.

Company News
Socket is proud to join the OpenJS Foundation as a Silver Member, deepening our commitment to the long-term health and security of the JavaScript ecosystem.

Security News
npm now links to Socket's security analysis on every package page. Here's what you'll find when you click through.