Skip to main content
Environment Variables are a way to store sensitive information that your application needs to function. This could be anything from API keys to Database credentials. FrogBot allows you to easily use Environment Variables within your config and throughout your application.

Next.js Applications

If you are using Next.js, no additional setup is required other than creating your .env file. To use Environment Variables, add a .env file to the root of your project:
Here is an example of what an .env file might look like:
To use Environment Variables in your FrogBot Config, you can access them directly from process.env:

Typed environment variables

Use defineEnv to parse and validate your server-side environment when your application starts. It reports all invalid or missing variables together and returns a typed, frozen object. Create src/env.ts:
Then use the resolved values in your FrogBot config:
This replaces fallback expressions such as process.env.FROGBOT_SECRET || '' with values that have already been validated.

Builders and modifiers

The env factory provides these builders: Every builder returns an immutable builder, so each modifier returns a new one. Without a modifier, an unset variable resolves to undefined. frogbotEnv includes these common builders: You can replace a base builder after spreading frogbotEnv:

Names and parsing

Property names become uppercase environment variable names with underscores before uppercase letters. For example, apiUrl becomes API_URL, gitSha1 becomes GIT_SHA1, and s3Bucket becomes S3_BUCKET. Use .name() when the environment variable follows another convention. Empty strings count as unset values. This is stricter than provider SDKs that may accept an empty API key as present. Numbers use JavaScript number parsing, so PORT=0 resolves to 0 and invalid numbers fail validation. Boolean parsing is case-insensitive and accepts:
  • True: 1, on, t, true, y, yes
  • False: 0, f, false, n, no, off
Other boolean values fail validation. When NODE_ENV=test, required checks are skipped so tests do not need every application secret. Present values are still parsed and can still produce validation errors.

Client-side Environments

For security and safety reasons, the Admin Panel does not include Environment Variables in its client-side bundle by default. Next.js provides a mechanism to expose Environment Variables to the client-side bundle when needed. If you are building a custom component and need to access Environment Variables from the client side, prefix them with NEXT_PUBLIC_.
Important: Be careful about what variables you provide to your client-side code. Analyze every single one to make sure that you’re not accidentally leaking sensitive information. Only ever include keys that are safe for the public to read in plain text.
For example, if you’ve got the following Environment Variable:
This key will automatically be made available to the client-side FrogBot bundle and can be referenced in your Custom Component as follows:
For more information, check out the Next.js documentation.

Outside of Next.js

If you are using FrogBot outside of Next.js, we suggest using the dotenv package to handle Environment Variables from .env files. This will automatically load your Environment Variables into process.env. To do this, import the package as high up in your application as possible:
Tip: Be sure that dotenv can find your .env file. By default, it will look for a file named .env in the root of your project. If you need to specify a different file, pass the path into the config options.