search

View as MarkdownOpen in Claude

Static method that searches for a config file across service-specific paths, caller-supplied directories, and default standard locations. Returns a loaded ConfigLoader as soon as the first existing file is found, or null if none of the candidates exist.

Default search paths (joined with filename, in order):

  • ${cwd}/${filename}
  • ${cwd}/config/${filename}
  • $HOME/.signalwire/${filename}
  • ${cwd}/.swml/${filename}
  • $HOME/.swml/${filename}
  • /etc/swml/${filename}

When serviceName is provided, two service-specific variants are checked before any other path:

  • ${cwd}/${serviceName}_${filename}
  • ${cwd}/.swml/${serviceName}_${filename}

When additionalPaths is provided, those directories are checked (joined with filename) after the service-specific variants but before the defaults.

Parameters

filename
stringRequired

The config file name to search for (e.g., "config.json").

additionalPaths
string[]

Extra directories to search before the default locations. Each directory is joined with filename to form a candidate path.

serviceName
string

Optional service name. When provided, adds ${serviceName}_${filename} variants to the front of the search order so a service can override the generic config file.

Returns

ConfigLoader | null — A loaded ConfigLoader instance, or null if no candidate path exists.

Example

1import { ConfigLoader } from '@signalwire/sdk';
2
3const config = ConfigLoader.search('agent-config.json', ['/etc/myapp'], 'myservice');
4if (config) {
5 console.log('Config found at:', config.getFilePath());
6 console.log('Port:', config.get<number>('server.port', 3000));
7} else {
8 console.log('No config file found');
9}