Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
config-from-schema
Advanced tools
A tool for building an application object from config files, command line arguments, or environment variables based on an OpenAPI compatible schema definition.
A tool for building an application object from config files, command line arguments, or environment variables based on an OpenAPI compatible schema definition.
Config schema format is defined in the OpenAPI Config Extension Specification.
Install
yarn add config-from-schema
Create schema
// schema.js
const schema = {
'x-config': [
{
name: 'port',
description: 'Application port',
default: 3000,
schema: {
type: 'integer'
}
},
{
name: 'secret',
description: 'Secret used for signing session cookies',
required: true,
schema: {
type: 'string'
}
}
]
}
export default schema
Build config
// app.js
import schema from './schema'
import configFromSchema from 'config-from-schema'
const config = configFromSchema('foo', schema)
console.info(config.port, config.secret)
Run app
Provide values via CLI args
$ node app --secret foo
3000 'foo'
OR via environment variables
FOO_SECRET=bar node app
3000 'bar'
OR via a config file
cat ~/.sso.json | jq .
$ cat ~/.foo.json
{
"secret": "baz"
}
$ node app
3000 'baz'
View docs
$ node app --help
Usage: app [options]
Options:
--help Show help [boolean]
--config Path to config file
[string] [default: "~/.foo.json"]
--port Application port [default: 3000]
--secret Secret used for signing session cookies [string] [required]
FAQs
A tool for building an application object from config files, command line arguments, or environment variables based on an OpenAPI compatible schema definition.
We found that config-from-schema 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.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.