Service
configuration is fetched from $PROJECT_ROOT/config/$NODE_ENV/config.json5
by the service execution procedure.
JSON5 format is used which is basically less strict javascript-like JSON
.
General description of service configuration options is defined by the ajv validation schema.
Extra configuration features whithin the config.json5
are described in the bi-config package.
// $PROJECT_ROOT/index.js
const Service = require('bi-service');
const config = require('bi-config');
const service = new Service(config);
service.config.get() //returns contents of $PROJECT_ROOT/config/$NODE_ENV/config.json5
service.config.get('storage:postgres'); //returns nested value of the postgres property
Each App
of AppManager
has its own configuration scope which is populated with service.config.get('apps:<app_name>')
once on the App initialization.
service.appManager.get('myapp').config.get() //returns value of service.config.get('apps:myapp')
Basic config.json5 example
{
exitOnInitError: true, //whether process should be terminated when an error occurs during service initialization
apps: {
<appname>: {
baseUrl: 'http://127.0.0.1:3000',
listen: 3000,
stopOnError: false,
doc: { //sub-app responsible for generating documentation for its parent app
baseUrl: 'http://127.0.0.1:3001',
listen: 3001,
name: 'docs',
title: '<appname>',
stopOnError: true,
tryItOut: true
},
response: {$ref: '#/response'},
bodyParser: {$ref: '#/bodyParser'},
}
},
response: {
headers: [
["Access-Control-Allow-Methods", "GET, POST, OPTIONS, PUT, PATCH, DELETE, CONNECT"]
]
},
bodyParser: {
json: {
extended: true,
type: 'application/json',
limit: "2mb"
},
urlencoded: {
type: 'application/x-www-form-urlencoded',
limit: "2mb",
extended: false
}
},
storage: {
postgres: {
host: "127.0.0.1",
ssl: false,
databases: {
main: {
db: "test",
username: "test",
password: "",
}
}
}
},
logs: {
exitOnError: false, // determines whether a process will exit with status code 1 on 'uncaughtException' event
transports: [
{
type: 'file',
level: 'info', // maximum log level of this sepecific transport, [optional]
json: false,
priority: 1,
dir: 'logs', // can be absolute or relative to the node's process
autocreate: true // whether the `dir` should be created if it does not exist
},
]
}
}