Security News
Supply Chain Attack Detected in Solana's web3.js Library
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
config-decorators
Advanced tools
This is a configuration helper library that enables the efficient management of default dev settings and prod settings from environment variables. Useful for separating dev and prod environments, dockerization, etc.
npm i config-decorators -S
ENV
or CLI
decorator to define overrides if the ENV variable / CLI argument is availableloadConfig
call
Aaand... Done!
Config class
import { loadConfig, ENV } from './config-decorators';
export class Config {
@ENV('MONGO_URL')
mongoUrl = 'mongodb://localhost/test2';
// Use it with a transform function
@ENV('SERVER_PORT', parseInt)
port = 8080;
// Or use the 'number' shortcut
@ENV('SERVER_PORT_2', 'number')
@CLI('port2')
port2 = 8081;
// Rules for boolean values:
// '0', '', 'false' will be parsed as `false`.
// Everything else will be `true`.
@ENV('ENABLE_AUTH', 'boolean')
@CLI('enable-auth')
enableAuth = true;
}
export const config = loadConfig(Config);
Import
import * as mongoose from 'mongoose';
import { config } from './config';
mongoose.connect(config.mongoUrl);
Note that CLI has higher priority than ENV. test.js
:
class CliTest1 {
@CLI('PATH')
@ENV('PATH')
path: string;
}
const config = loadConfig(CliTest1);
console.log(config.path);
When calling node test.js --PATH test
will print test
, not the PATH environmental variable.
The ENV/CLI variable can be required; loadConfig
will throw an error if there's no such ENV variable and no CLI argument.
Note that NOT the class decorators but the loadConfig
throws the error.
export class Config {
@ENV('MONGO_URL', true)
mongoUrl: string;
@ENV('SERVER_PORT', parseInt, true)
port: number;
}
// Here comes the error
export const config = loadConfig(Config);
The main stuff is at loadConfig
:
ENV
or CLI
decorators
npm i
npm run build
-- You should have tsc
(TypeScript) in your PATHnpm run test
Tested on Node.js with TypeScript (2.1.4+) classes, ES6 build.
Create an issue if you need something.
Validation
@ENV('SERVER_PORT', parseInt)
@Validate(value => value > 1000)
port = 8080;
Print help
if (config.help) {
printHelp(ConfigClass1, ConfigClass2); // <- here
return;
}
Wider interface to minimist, e.g. aliases
2018-12-05 v0.2.0 Boolean parsing fix
Boolean values will be parsed as boolean values so SOME_ENV=false
will be false
.
SOME_ENV=0
or SOME_ENV=
also remains false
.
Everything else will be parsed as true
.
Dev deps are updated.
FAQs
Decorator lib for ENV-based configuration
The npm package config-decorators receives a total of 221 weekly downloads. As such, config-decorators popularity was classified as not popular.
We found that config-decorators demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.