
Research
Two Malicious Rust Crates Impersonate Popular Logger to Steal Wallet Keys
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
@miroculus/config
Advanced tools
Configure your node apps in a clear, easy and type safe way. Just define the configuration values with the types you want to have, and set them using environment variables or setting them on an `.env` file.
Configure your node apps in a clear, easy and type safe way. Just define the configuration
values with the types you want to have, and set them using environment variables or
setting them on an .env
file.
Install it:
npm install @miroculus/config
Somewhere on your project, create a file where you define and load your configuration
values, for example on src/config.js
:
const loadConfig = require('@miroculus/config')
module.exports = loadConfig({
PORT: { type: 'number', default: 3000 },
TLS_ENABLED: 'boolean',
MONGODB_URI: { type: 'string', default: 'mongodb://localhost/database' },
PASSWORD_SALT: { type: 'string', required: true },
AUTH: { type: 'json', default: () => ({ user: 'admin', password: 'admin' }) }
})
Then, you can set you configs using environment variables, or creating a file on the
root of you project named .env
(Thanks dotenv
):
PORT=8080
TLS_ENABLED=true
MONGODB_URI=mongodb://localhost/myCustomName
PASSWORD_SALT=somethingreallylongplease
AUTH={ "user": "admin", "password": "some-complicated-password" }
Then, just use it:
const config = require('./src/config')
config.PORT === 8080 // true
!!config.TLS_ENABLED // true
config.MONGODB_URI === 'mongodb://localhost/myCustomName' // true
config.AUTH.user === 'admin' // true
config.AUTH.password === 'some-complicated-password' // true
For each configuration value you can define it's type
, if it is required
, or if
it has a default
value. This are all the possible options:
Schema.type
string
BAR= value foo
=> config.BAR === 'value foo'
number
Number
PORT=3000
=> config.PORT === 3000
NUMBER=3.2
it will throw an error)NUMBER=-32
0
✅00
❌0123
❌12300
✅-123
✅-0
✅boolean
true
or false
True
or TRUE
required
, its value will be undefined
, unless it has a default
value.json
JSON.parse
VAL={"some": "json-value"}
VAL=["an", "array", "of", "strings"]
VAL={}
VAL=[]
array
string
s.type: 'string'
but the value will be splitted and trimmed using val.split(',').map((str) => str.trim())
VAL=a, b, c
will be parsed to config.VAL = ['a', 'b', 'c']
Schema.default
The default config is to set a value when something is not configured, it can take any value to set, or a function that will be executed and the result setted. e.g.:
PORT: { type: 'number', default: 3000 }
PORT: { type: 'number', default: () => randomNumberBetween(3000, 8000) }
Schema.required
You can set your value as required: true
if you want to throw an error when a
value is not setted, or its setted to an empty value.
Schema.validate
This props serves to add a custom validation for the given value. It can be a function
that should return true
or false
, or a RegExp
. e.g. both of the following validations
check that the configured value is 1
, 2
or 3
:
module.exports = loadConfig({
STRING_VALIDATE: { type: 'number', validate: (val, key, config) => [1, 2, 3].includes(val)},
REGEXP_VALIDATE: { type: 'number', validate: /^(1|2|3)$/ }
})
Schema.enum
The enum property allows you to set a finite set of value that the given configuration can have. e.g.:
module.exports = loadConfig({
LOG_LEVEL: { type: 'string', enum: ['debug', 'info', 'warn', 'error'] }
})
npm run test
npm run test:watch # for development purposes
MIT
FAQs
Configure your node apps in a clear, easy and type safe way. Just define the configuration values with the types you want to have, and set them using environment variables or setting them on an `.env` file.
The npm package @miroculus/config receives a total of 31 weekly downloads. As such, @miroculus/config popularity was classified as not popular.
We found that @miroculus/config demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 9 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
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
Research
A malicious package uses a QR code as steganography in an innovative technique.
Research
/Security News
Socket identified 80 fake candidates targeting engineering roles, including suspected North Korean operators, exposing the new reality of hiring as a security function.