
Product
Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain
Socket Firewall is a free tool that blocks malicious packages at install time, giving developers proactive protection against rising supply chain attacks.
@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=[]
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.
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 34 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.
Product
Socket Firewall is a free tool that blocks malicious packages at install time, giving developers proactive protection against rising supply chain attacks.
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.