Configuration
Watt is configured with a configuration file. It supports the use of environment variables as setting values with environment variable placeholders.
Configuration Files
Watt automatically detects and loads configuration files found in the current working directory with the file names listed here.
Alternatively, you can use the --config
option to specify a configuration file path for most wattpm
CLI commands. The configuration examples in this reference use the JSON format.
Supported File Formats
For detailed information on supported file formats and extensions, please visit our Supported File Formats and Extensions page.
Settings
Configuration settings containing sensitive data should be set using environment variable placeholders.
The autoload
and applications
settings can be used together, but at least one
of them must be provided. When the configuration file is parsed, autoload
configuration is translated into applications
configuration.
autoload
The autoload
configuration is intended to be used with monorepo applications.
autoload
is an object with the following settings:
path
(required,string
) - The path to a directory containing the microservices to load. In a traditional monorepo application, this directory is typically namedpackages
.exclude
(array
ofstring
s) - Child directories insidepath
that should not be processed.mappings
(object
) - Each microservice is given an ID and is expected to have a Platformatic configuration file. By default, the ID is the microservice's directory name, and the configuration file is expected to be a well-known Platformatic configuration file.mappings
can be used to override these default values.id
(required,string
) - The overridden ID. This becomes the new microservice ID.- **
config
(string
) - The overridden configuration file. name. This is the file that will be used when starting the microservice. useHttp
(boolean
) - The application will be started on a random HTTP port on127.0.0.1
, and exposed to the other applications via that port and on default, it is set tofalse
.workers
(number
) - The number of workers to start for this application. If the application is the entrypoint or if the runtime is running in development mode this value is ignored and hardcoded to1
.health
(object): Configures the health check for each worker of the application. It supports all the properties also supported in the runtime health property. The values specified here overrides the values specified in the runtime.preload
(string
orarray
ofstring
s): A file or a list of files to load before the application code.arguments
(array
ofstring
s) - The arguments to pass to the application. They will be available inprocess.argv
.nodeOptions
(string
): TheNODE_OPTIONS
to apply to the application. These options are appended to any existing option.dependencies
(array
ofstring
s): A list of applications that must be started before attempting to start the current application. Note that the runtime will not perform any attempt to detect or solve dependencies cycles.
preload
The preload
configuration is intended to be used to register
Application Performance Monitoring (APM) agents. preload
should contain
a path or a list of paths pointing to a CommonJS or ES module that is loaded at the start of
the app worker thread.
applications
applications
is an array of objects that defines the microservices managed by the
runtime. Each application object supports the following settings:
id
(required,string
) - A unique identifier for the microservice. When working with the Platformatic Gateway, this value corresponds to theid
property of each object in theapplications
section of the config file. When working with client objects, this corresponds to the optionalapplicationId
property or thename
field in the client'spackage.json
file if aapplicationId
is not explicitly provided.path
(required,string
) - The path to the directory containing the microservice. It can be omitted ifurl
is provided.url
(required,string
) - The URL of the application remote GIT repository, if it is a remote application. It can be omitted ifpath
is provided.gitBranch
(string) - The branch of the application to resolve.config
(string
) - The configuration file used to start the microservice.useHttp
(boolean
) - The application will be started on a random HTTP port on127.0.0.1
, and exposed to the other applications via that port, on default it is set tofalse
. Set it totrue
if you are using @fastify/express.workers
(number
) - The number of workers to start for this application. If the application is the entrypoint or if the runtime is running in development mode this value is ignored and hardcoded to1
.health
(object): Configures the health check for each worker of the application. It supports all the properties also supported in the runtime health property. The values specified here overrides the values specified in the runtime.arguments
(array
ofstring
s) - The arguments to pass to the application. They will be available inprocess.argv
.envfile
(string
) - The path to an.env
file to load for the application. By default, the.env
file is loaded from the application directory.env
(object
) - An object containing environment variables to set for the application. Values set here takes precedence over values set in theenvfile
.sourceMaps
(boolean
) - Iftrue
, source maps are enabled for the application. Default:false
.packageManager
(string
) - The package manager to use when using theinstall-dependencies
or theresolve
commands ofwattpm-utils
. Default is to autodetect it, unless it is specified via command line.preload
(string
orarray
ofstring
s): A file or a list of files to load before the application code.nodeOptions
(string
): TheNODE_OPTIONS
to apply to the application. These options are appended to any existing option.dependencies
(array
ofstring
s): A list of applications that must be started before attempting to start the current application. Note that the runtime will not perform any attempt to detect or solve dependencies cycles.telemetry
(object
): containing aninstrumentations
array to optionally configure additional open telemetry intrumentations per application, e.g.:
"applications": [
{
"id": "api",
"path": "./services/api",
"telemetry": {
"instrumentations": ["@opentelemetry/instrumentation-express"]
}
}
]
It's possible to specify the name of the export of the instrumentation and/or the options:
"applications": [
{
"id": "api",
"path": "./services/api",
"telemetry": {
"instrumentations": [{
"package": "@opentelemetry/instrumentation-express",
"exportName": "ExpressInstrumentation",
"options": {}
}]
}
}
]
An alias for applications
. If both are present, their content will be merged.
It's also possible to disable the instrumentation by setting the enabled
value property to false
(env variables are also supported):
"applications": [
{
"id": "api",
"path": "./services/api",
"telemetry": {
"enabled": "false",
"instrumentations": [{
"package": "@opentelemetry/instrumentation-express",
}]
}
}
]
env
An object containing environment variables to set for all applications in the
runtime. Any environment variables set in the env
object will be merged with
the environment variables set in the envfile
and env
properties of each
application, with application-level environment variables taking precedence.
sourceMaps
If true
, source maps are enabled for all applications. Default: false
. This setting can be overridden at the application level.
resolvedServicesBasePath
The base path, relative to the configuration file to store resolved applications. Each application will be saved in {resolvedServicesBasePath}/{id}
. Default: external
.
entrypoint
The Platformatic Runtime's entrypoint is a microservice that is exposed
publicly. This value must be the ID
of an application defined via the autoload
or
applications
configuration.
workers
The default number of workers to start per each application. It can be overriden at application level.
This value is hardcoded to 1
if the runtime is running in development mode or when applying it to the entrypoint.
workersRestartDelay
Configures the amount of milliseconds to wait before replacing another worker of an application during a restart.
gracefulShutdown
Configures the amount of milliseconds to wait before forcefully killing an application or the runtime.
The object supports the following settings:
application
(number
) - The graceful shutdown timeout for an application.runtime
(number
) - The graceful shutdown timeout for the entire runtime.
For both the settings the default is 10000
(ten seconds).
watch
An optional boolean, set to default false
, indicating if hot reloading should
be enabled for the runtime. If this value is set to false
, it will disable
hot reloading for any microservices managed by the runtime. If this value is
true
, then hot reloading for individual microservices is managed by the
configuration of that microservice.
Note that watch
should be enabled for each individual application in the runtime.
While hot reloading is useful for development, it is not recommended for use in production.