Environment Variables

Environment variables are key-value pairs that can be defined outside your application’s source code. These variables give the following advantages :

  • Security : Environment variables help keep sensitive information safe. Things like API keys, tokens, and database credentials should never be stored directly in your code, as anyone with access to your code could see them. Instead, environment variables store these secrets securely, keeping them out of your codebase.

  • Configuration Flexibility : By using environment variables, you can easily switch settings based on the deployment environment. For example, you might use a different API endpoint for local development than for production, or toggle debugging tools on and off. This flexibility lets you control how your app behaves in different scenarios without modifying the code.

  • Scalability : Environment variables allow you to create reusable configurations. If you have multiple projects that share similar settings (like API keys or endpoints), you can define those settings once as environment variables and use them across projects, making your setup much easier to manage.

Where to Use Environment Variables

Environment variables are typically used in these areas:

  1. API Keys and Endpoints: Store keys and endpoints to external services, like third-party APIs (e.g., REACT_APP_API_KEY, REACT_APP_BASE_URL). This way, sensitive information is kept secure, and you can swap out endpoints based on the deployment environment.

  2. Feature Flags: If you want to enable conditionally or disable certain features, environment variables can act as feature flags. For example, setting REACT_APP_ENABLE_NEW_FEATURE to true or false allows you to toggle features without changing the code.

Best practices

Here are two key practices you can follow to ensure your application remains secure throughout its lifecycle:

  • Regularly review and rotate your API keys and other secrets to maintain security.
  • Configure different values for variables in development, preview, and production environments to ensure proper isolation and security.

Create Environment Variables

You can create environment variables for your applications directly from the Catalyst console. The environment variables of applications deployed using private Git Integration, Slate templates, or public repository integration will be created in Catalyst’s development environment by default.

Please follow the below steps to create environment variables in Slate:

  1. Click on any deployment, and navigate to the Configuration tab in the left pane and expand Environment Variables.
add-environment-variables
  1. Click Add Variable.
sync-now-button-private
  1. Click Save.
show-environment-variables

You can add any number of variables as required for your application.

Note: To call the environment variables during your application deployment, please make sure to use the following syntax:process.env.[variable_name]

Create Variables in Production

If you have deployed your Catalyst project to production, you can create environment variables specific to the production environment, if required. You can use the same above mentioned steps to create variables in production.

Note: You will not be able to access production variables in your application if your production environment is disabled.

Last Updated 2025-04-22 18:24:36 +0530 +0530