Balena Settings Client

6.0.3 · active · verified Wed Apr 22

balena-settings-client is a low-level utility module designed to provide read-only access to user-configurable balena application settings. It consolidates configuration from various sources, including default settings, user-specific `.balenarc.yml` files (e.g., `$HOME/.balenarc.yml` on Unix), project-specific `.balenarc.yml` files (`$PWD/balenarc.yml`), and environment variables prefixed with `BALENARC_`. Values are merged with a clear precedence hierarchy, allowing for flexible overrides. The current stable version is 6.0.3, with recent releases indicating active maintenance and development. Key differentiators include its role in the balena ecosystem for managing client-side settings, its ability to merge configurations from multiple sources, and its explicit read-only nature. This module is not intended for direct end-user consumption; instead, users are typically directed to the higher-level `balena-sdk` for interacting with balena services.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the balena-settings-client, read individual settings using `settings.get()`, and retrieve all loaded settings with `settings.getAll()`. It shows how settings from a local `balenarc.yml` file and environment variables are automatically merged and accessed.

import settings from 'balena-settings-client';
import * as fs from 'fs';
import * as path from 'path';

// Create a dummy .balenarc.yml in the current working directory for demonstration
const cwdBalenarcPath = path.join(process.cwd(), 'balenarc.yml');
fs.writeFileSync(cwdBalenarcPath, 'projectsDirectory: "/tmp/my-projects-dir"\n');

// Simulate an environment variable
process.env.BALENARC_CUSTOM_SETTING = 'some-custom-value';

async function demonstrateSettings() {
  console.log('--- Reading individual settings ---');
  const balenaUrl = settings.get('balenaUrl');
  console.log(`balenaUrl: ${balenaUrl || 'Not set (default)'}`);

  const projectsDirectory = settings.get('projectsDirectory');
  console.log(`projectsDirectory (from CWD config): ${projectsDirectory}`);

  const customSetting = settings.get('customSetting');
  console.log(`customSetting (from ENV): ${customSetting}`);

  console.log('\n--- Reading all settings ---');
  const allSettings = settings.getAll();
  console.log(JSON.stringify(allSettings, null, 2));

  // Clean up the dummy file
  fs.unlinkSync(cwdBalenarcPath);
}

demonstrateSettings().catch(console.error);

view raw JSON →