Using Environment Variables
Environment variables act as global variables accessible throughout your application, providing configurable settings and data that remain consistent across different parts of the system.
Environment variables prefixed with PUBLIC_NEXT_ are utilized specifically by client-side code.
//access client-side variablesconst databaseId = process.env.NEXT_PUBLIC_APPWRITE_DATABASE_ID;Environment variables not prefixed with PUBLIC_NEXT_ are designated for server-side code.
//access client-side variablesconst databaseId = process.env.APPWRITE_DATABASE_ID;Environment variables
31SaaS includes all the environment variables necessary to run a demo app:
NEXT_PUBLIC_ENVIRONMENT: Set toprodfor Production.envanddevfor development.env.local. Used to control functions that should only run in one environment.NEXT_PUBLIC_APP_URL: The URL of your application. Used for generating absolute URLs, such as for redirects or links.APPWRITE_ENDPOINT: The API endpoint for your Appwrite backend service.APPWRITE_PROJECT_ID: The ID of the project in your Appwrite backend.APPWRITE_API_KEY: The API key used to authenticate requests to your Appwrite backend.APPWRITE_DATABASE_ID: The ID of the database in your Appwrite project.NEXT_PUBLIC_APPWRITE_DATABASE_ID: Same asAPPWRITE_DATABASE_ID, but for client-side code.NEXT_PUBLIC_APPWRITE_ENDPOINT: Same asAPPWRITE_ENDPOINT, but for client-side code.NEXT_PUBLIC_APPWRITE_PROJECT_ID: Same asAPPWRITE_PROJECT_ID, but for client-side code.STRIPE_PUBLISHABLE_KEY: The publishable API key provided by Stripe.STRIPE_SECRET_KEY: The secret API key provided by Stripe.STRIPE_WEBHOOK_SECRET: The secret used to verify webhook events sent by Stripe.STRIPE_PRICE_FREE: Hardcode tofreeor update to Stripe’sprice idof the product.STRIPE_PRICE_PRO: Theprice idfor the pro subscription plan in your Stripe account.NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY: Same asSTRIPE_PUBLISHABLE_KEY, but for client-side code.NEXT_PUBLIC_STRIPE_PRICE_FREE: Hardcode tofreeor update to Stripe’sprice idof the product.NEXT_PUBLIC_STRIPE_PRICE_PRO: Theprice idfor the pro subscription plan in your Stripe account.RESEND_API_KEY: The API key used to authenticate requests to the Resend service.RESEND_SENDER_EMAIL: The email address used as the sender for emails sent through the Resend service.
Setting Environment Variables
Development Mode
For local testing, follow the below steps to setup the enviroment variables.
- Copy the
.env.examplefile provided in the project to a new file named.env.local. This file will contain your local development environment variables. - Open the
.env.localfile in a text editor and update the variables according to your local development environment. This may include database, API keys, or any other configuration variables specific to your development setup.
Production Mode
When you’re ready to deploy your project to production, follow these additional steps:
- Copy the contents of the
.env.localfile to a new file named.env. This file will contain your production environment variables. - Update
.envwith Production values.