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:
.env file might look like:
process.env:
Typed environment variables
UsedefineEnv 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:
process.env.FROGBOT_SECRET || '' with values that have already been validated.
Builders and modifiers
Theenv 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
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 withNEXT_PUBLIC_.
For example, if you’ve got the following Environment Variable:
Outside of Next.js
If you are using FrogBot outside of Next.js, we suggest using thedotenv 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: