ConfigProvider that is compatible with the Convex runtime, where process.env is not enumerable. Confect sets it automatically for every function that runs in the Convex runtimeâqueries, mutations, actions, and HTTP API handlersâso Effectâs Config module works out of the box.
Node actions are the exception. They run in the Node.js runtime, where process.env behaves like an ordinary object, so they use Effectâs default ConfigProvider.fromEnv instead. Reading environment variables works the same way in both runtimes.
Reading environment variables
UseConfig from Effect to read Convex environment variables in your function handlers.
confect/settings.impl.ts
Config.string, Config.number, Config.boolean, Config.withDefault, Config.option, and Config.nested, among others.
Collections
Config.Array and Config.Record read a collection from a single delimited variable, so they work in the Convex runtime like any other combinator. Pass them to Config.schema with the variableâs name.
Given ALLOWED_ORIGINS="https://a.example,https://b.example":
FEATURE_LIMITS="uploads=10,exports=5":
"," as the separator, and Config.Record to "=" between key and value; pass separator or keyValueSeparator to change them. Neither trims whitespace around elements, so write the variable without spaces after the separator, or map over the result to trim.
The collection has to live in one variable. Effectâs default provider can also assemble one from several variablesâORIGINS_0 and ORIGINS_1 for an array, FEATURE_LIMITS_UPLOADS for a recordâbecause it reads the whole environment and discovers the keys under a prefix. Confectâs provider resolves each config path to a single variable and never reports child keys, so that spread-out form fails with Expected array at ["ORIGINS"] or Expected object at ["FEATURE_LIMITS"]. It works in Node actions, which use the default provider; avoid it if the handler might later move to the Convex runtime.
Custom config provider
TheConvexConfigProvider module is exported from @confect/server. ConvexConfigProvider.make() takes no arguments and returns the provider Confect already installs for you.
"_". Config.nested(Config.string("KEY"), "API") therefore reads API_KEY. An empty string counts as a missing value, so Config.withDefault and Config.option recover from it.
To override the provider for part of a handler, provide ConfigProvider.ConfigProvider as a service.
confect/settings.impl.ts