Skip to content

About

Capacitor plugin to store and read env var in capacitor config, helpfull for multitenant app.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

11 stars

Watchers

1 watching

Forks

@capgo/capacitor-env

Read environment values from your Capacitor config at runtime, so one codebase can ship as many white label or multi-tenant apps with different settings.

Capgo - Instant updates for Capacitor

Capgo: push fixes to your Capacitor users in minutes, build signed iOS and Android apps without a Mac, and roll back in one click.

14-day unlimited free trial. No credit card required

Missing a feature? We'll build the plugin for you 💪

@capgo/capacitor-env for Capacitor apps

Key features

  • Runtime config: getKey() returns a value you set in the plugin section of capacitor.config.
  • White label friendly: keep the same web code and change only the native config per app.
  • Native read: values come from the Capacitor plugin config on iOS and Android.
  • Safe default: a missing key returns an empty string.
  • Platforms: iOS and Android. On web, getKey() returns an empty string.

Documentation

The most complete doc is available here: https://capgo.app/docs/plugins/env/

Compatibility

Plugin version Capacitor compatibility Maintained
v8.*.* v8.*.* ✅
v7.*.* v7.*.* On demand
v6.*.* v6.*.* ❌
v5.*.* v5.*.* ❌

Note: The major version of this plugin follows the major version of Capacitor. Use the version that matches your Capacitor installation (e.g., plugin v8 for Capacitor 8). Only the latest major version is actively maintained.

Install

You can use our AI-Assisted Setup to install the plugin. Add the Capgo skills to your AI tool using the following command:

npx skills add https://github.com/cap-go/capacitor-skills --skill capacitor-plugins

Then use the following prompt:

Use the `capacitor-plugins` skill from `cap-go/capacitor-skills` to install the `@capgo/capacitor-env` plugin in my project.

If you prefer Manual Setup, install the plugin by running the following commands and follow the platform-specific instructions below:

npm install @capgo/capacitor-env
npx cap sync

API

Capacitor plugin for accessing environment variables in native code.

This plugin provides a secure way to access environment variables that were compiled into the native application at build time. Environment variables can be configured during the build process and accessed at runtime without exposing them in the web bundle.

getKey(...)

getKey(options: { key: string; }) => Promise<{ value: string; }>

Retrieves the value of a specific environment variable by key.

This method fetches environment variables that were set during the native build process. The variables must be configured in the native project before they can be accessed at runtime.

Param Type Description
options { key: string; } - Configuration object containing the environment variable key

Returns: Promise<{ value: string; }>


getPluginVersion()

getPluginVersion() => Promise<{ version: string; }>

Get the version of the native Capacitor plugin.

This method returns the current version of the capacitor-env plugin that is installed in the native application. Useful for debugging and ensuring compatibility between the web and native components.

Returns: Promise<{ version: string; }>


About

Capacitor plugin to store and read env var in capacitor config, helpfull for multitenant app.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

11 stars

Watchers

1 watching

Forks

Releases

Sponsor this project

Packages

Contributors

Languages