Skip to main content
Version: Next

Using Environment Variables with Platformatic

Applications built with Platformatic loosely follows the twelve factor app methodology. This guide will show how to make your application configurable, while keeping your deployment environments as close as possible.

Environment Variables replacement

In any Platformatic configuration file, you can always interpolate an environment variable inside a value:

{
...
"server": {
"port": "{PORT}"
}
...
}

The replacement is done via pupa, after the JSON file is parsed.

All Platformatic configuration files support Environment Variables replacement.

dotenv support

dotenv is built in inside Platformatic, allowing you to create an envfile with all your environment variables, that is loaded automatically by Platformatic at startup. If a .env file exists it will automatically be loaded by Platformatic using dotenv. For example:

.env
PORT=3000

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:

PORT=4042 npx wattpm start