findConfigFile

View as MarkdownOpen in Claude

Static helper that searches for a config file and returns the first match’s absolute path without loading it. Useful for detecting whether a configuration exists before deciding whether to instantiate a ConfigLoader. For searching from an instance that also loads on match, use search() instead.

The search order is:

  1. {serviceName}_config.json (cwd) and .swml/{serviceName}_config.json (if serviceName)
  2. Each path in additionalPaths (if provided)
  3. config.json
  4. agent_config.json
  5. .swml/config.json
  6. ~/.swml/config.json
  7. /etc/swml/config.json

Parameters

serviceName
string | undefined

Service name. When provided, service-specific config filenames are checked before defaults.

additionalPaths
string[] | undefined

Extra file paths to check between service-specific and default locations.

Returns

string | null — absolute path of the first existing config file, or null if none match.

Example

1import { ConfigLoader } from '@signalwire/sdk';
2
3const path = ConfigLoader.findConfigFile('my-service');
4if (path) {
5 const loader = new ConfigLoader(path);
6 console.log(`Loaded from ${loader.getFilePath()}`);
7} else {
8 console.log('No config file found');
9}