Configuration
Platformatic Service configured with a configuration file. It supports the use of environment variables as setting values with configuration placeholders.
Configuration Files
The Platformatic CLI automatically detects and loads configuration files found in the current working directory with the file names listed here.
Alternatively, you can specify a configuration file path using the --config option 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, such as database connection URLs and passwords, should be set using configuration placeholders.
basePath
Application proxy base path when exposing this application in a gateway when setting the proxy property.
If not specified, the application will be exposed on the application or a value specified in the application code via platformatic.setBasePath().
server
An object with the following settings:
- 
hostname— Hostname where Platformatic Service server will listen for connections.
- 
port— Port where Platformatic Service server will listen for connections.
- 
healthCheck(booleanorobject) — Enables the health check endpoint.- Powered by @fastify/under-pressure.
- The value can be an object, used to specify the interval between checks in milliseconds (default: 5000)
 Example {
 "server": {
 ...
 "healthCheck": {
 "interval": 2000
 }
 }
 }
- Powered by 
- 
cors(object) — Configuration for Cross-Origin Resource Sharing (CORS) headers.- All options will be passed to the @fastify/corsplugin. In order to specify aRegExpobject, you can pass{ regexp: 'yourregexp' }, it will be automatically converted
 
- All options will be passed to the 
- 
http2(boolean) — Enables HTTP/2 support. Default:false.
- 
https(object) - Configuration for HTTPS supporting the following options. Requireshttps.- allowHTTP1(- boolean) - If- true, the server will also accept HTTP/1.1 connections when- http2is enabled. Default:- false.
- key(required,- string,- object, or- array) - If- keyis a string, it specifies the private key to be used. If- keyis an object, it must have a- pathproperty specifying the private key file. Multiple keys are supported by passing an array of keys.
- cert(required,- string,- object, or- array) - If- certis a string, it specifies the certificate to be used. If- certis an object, it must have a- pathproperty specifying the certificate file. Multiple certificates are supported by passing an array of keys.
 
- 
logger(object) -- the logger configuration.
- 
pluginTimeout(integer) -- the number of milliseconds to wait for a Fastify plugin to load
- 
bodyLimit(integer) -- the maximum request body size in bytes
- 
maxParamLength(integer) -- the maximum length of a request parameter
- 
caseSensitive(boolean) -- iftrue, the router will be case-sensitive
- 
ignoreTrailingSlash(boolean) -- iftrue, the router will ignore the trailing slash
- 
connectionTimeout(integer) -- the milliseconds to wait for a new HTTP request
- 
keepAliveTimeout(integer) -- the milliseconds to wait for a keep-alive HTTP request
- 
maxRequestsPerSocket(integer) -- the maximum number of requests per socket
- 
forceCloseConnections(booleanor"idle") -- iftrue, the server will close all connections when it is closed
- 
requestTimeout(integer) -- the milliseconds to wait for a request to be completed
- 
disableRequestLogging(boolean) -- iftrue, the request logger will be disabled
- 
exposeHeadRoutes(boolean) -- iftrue, the router will expose HEAD routes
- 
serializerOpts(object) -- the serializer options
- 
requestIdHeader(stringorfalse) -- the name of the header that will contain the request id
- 
requestIdLogLabel(string) -- Defines the label used for the request identifier when logging the request. default:'reqId'
- 
jsonShorthand(boolean) -- default:true-- visit fastify docs for more details
- 
trustProxy(booleanorintegerorstringorString[]) -- default:false-- visit fastify docs for more details
See the fastify docs for more details.
plugins
An optional object that defines the plugins loaded by Platformatic Service.
- packages: : an array of packages/modules (- string) or an array of objects composed as follows:- name(- string): the name of the package to- import; required.
- options(- object): Optional plugin options.
 
- paths(optional,- array): an array of paths (- string) or an array of objects composed as follows,- path(- string): Relative path to plugin's entry point.
- options(- object): Optional plugin options.
- encapsulate(- boolean): if the path is a folder, it instructs Platformatic to not encapsulate those plugins.
- maxDepth(- integer): if the path is a folder, it limits the depth to load the content from.
- autoHooks(- boolean): Apply hooks from autohooks.js file(s) to plugins found in folder.
- autoHooksPattern(- string): Regex to override the autohooks naming convention.
- cascadeHooks(- boolean): If using autoHooks, cascade hooks to all children. Ignored if autoHooks is false.
- overwriteHooks(- boolean): If using cascadeHooks, cascade will be reset when a new autohooks.js file is encountered. Ignored if autoHooks is false.
- routeParams(- boolean): Folders prefixed with _ will be turned into route parameters.
- forceESM(- boolean): If set to 'true' it always use await import to load plugins or hooks.
- ignoreFilter(- string): Filter matching any path that should not be loaded. Can be a RegExp, a string or a function returning a boolean.
- matchFilter(- string): Filter matching any path that should be loaded. Can be a RegExp, a string or a function returning a boolean.
- ignorePattern(- string): RegExp matching any file or folder that should not be loaded.
- indexPattern(- string): Regex to override the index.js naming convention
 
- typescript(- booleanor- object): enable TypeScript compilation. A- tsconfig.jsonfile is required in the same folder. See TypeScript compilation options for more details.
Example
{
  "plugins": {
    "packages": [
      {
        "name": "@fastify/compress",
        "options": {
          "threshold": 1
        }
      }
    ],
    "paths": [
      {
        "path": "./my-plugin.js",
        "options": {
          "foo": "bar"
        }
      }
    ]
  }
}
watch
Enables watching for file changes if set to true or "true". When changes are detected, then the application will be restarted after loading changed files.
This is only available when executing within a Platformatic Runtime and if the runtime watch configuration is enabled.
It can also be customized with the following options:
- enabled(- booleanor- string): enables watching.
- 
ignore(string[], default:null): List of glob patterns to ignore when watching for changes. Ifnullor not specified, ignore rule is not applied. Ignore option doesn't work for typescript files.
- 
allow(string[], default:['*.js', '**/*.js']): List of glob patterns to allow when watching for changes. Ifnullor not specified, allow rule is not applied. Allow option doesn't work for typescript files.Example {
 "watch": {
 "ignore": ["*.mjs", "**/*.mjs"],
 "allow": ["my-plugin.js", "plugins/*.js"]
 }
 }
service
Configure @platformatic/service specific settings such as graphql or openapi:
- 
graphql(booleanorobject, default:false) — Controls the GraphQL API interface, with optional GraphiQL UI.Examples Enables GraphQL support {
 "service": {
 "graphql": true
 }
 }Enables GraphQL support with GraphiQL {
 "service": {
 "graphql": {
 "graphiql": true
 }
 }
 }
- 
openapi(booleanorobject, default:false) — Enables OpenAPI REST support.- If value is an object, all OpenAPI v3 allowed properties can be passed. Also, a prefixproperty can be passed to set the OpenAPI prefix.
- Platformatic Service uses @fastify/swaggerunder the hood to manage this configuration.
 Examples Enables OpenAPI {
 "service": {
 ...
 "openapi": true
 }
 }Enables OpenAPI with prefix {
 "service": {
 "openapi": {
 "prefix": "/api"
 }
 }
 }Enables OpenAPI with options {
 "service": {
 "openapi": {
 "info": {
 "title": "Platformatic Service",
 "description": "Exposing a SQL database as REST"
 }
 }
 }
 }
- If value is an object, all OpenAPI v3 allowed properties can be passed. Also, a 
telemetry
Open Telemetry is optionally supported with these settings:
- applicationName(required,- string) — Name of the application as will be reported in open telemetry.
- version(- string) — Optional version (free form)
- skip(- array). Optional list of operations to skip when exporting telemetry defined- objectwith properties:- method: GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS, TRACE
- path. e.g.:- /documentation/json
 
- exporter(- objector- array) — Exporter configuration. If not defined, the exporter defaults to- console. If an array of objects is configured, every object must be a valid exporter object. The exporter object has the following properties:- type(- string) — Exporter type. Supported values are- console,- otlp,- zipkinand- memory(default:- console).- memoryis only supported for testing purposes.
- options(- object) — These options are supported:- url(- string) — The URL to send the telemetry to. Required for- otlpexporter. This has no effect on- consoleand- memoryexporters.
- headers(- object) — Optional headers to send with the telemetry. This has no effect on- consoleand- memoryexporters.
 
 
Note that OTLP traces can be consumed by different solutions, like Jaeger. Here the full list.
Example
{
  "telemetry": {
    "applicationName": "test-application",
    "exporter": {
      "type": "otlp",
      "options": {
        "url": "http://localhost:4318/v1/traces"
      }
    }
  }
}
Environment variable placeholders
The value for any configuration setting can be replaced with an environment variable
by adding a placeholder in the configuration file, for example {PLT_SERVER_LOGGER_LEVEL}.
The value for any configuration setting can be replaced with an environment variable placeholder in a configuration file, such as {PORT}.
Example
{
  "server": {
    "port": "{PORT}"
  }
}
Platformatic will replace the placeholders in this example with the environment variables of the same name.
If no environment variable is found, then the placeholder will be replaced with an empty string. Note that this can lead to a schema validation error.
Setting Environment Variables
If a .env file exists it will automatically be loaded by Platformatic using
dotenv. For example:
PLT_SERVER_LOGGER_LEVEL=info
PORT=8080
The .env file must be located in the same folder as the Platformatic configuration
file or in the current working directory.
Environment variables can also be set directly on the command line, for example:
PLT_SERVER_LOGGER_LEVEL=debug wattpm dev
PLT_ROOT
The {PLT_ROOT} placeholder is automatically set to the directory containing the configuration file, so it can be used to configure relative paths.