Skip to main content

Environment Variables

Every ChurchApps project uses a .env file for local configuration. Each project includes a sample file that you copy and customize.

General Pattern

  1. Look for dotenv.sample.txt or .env.sample in the project root.
  2. Copy it to .env.
  3. Edit the values as needed.
# Example for a project with .env.sample
cp .env.sample .env

# Example for a project with dotenv.sample.txt
cp dotenv.sample.txt .env
warning

Never commit .env files to version control. They contain secrets such as database credentials, API keys, and JWT secrets. All ChurchApps projects include .env in .gitignore, but always double-check before committing.

Choosing an API Target

The most important decision is where your frontend points for API calls. There are two options:

Use the shared staging environment. No local API or database setup needed.

# Base URL pattern
https://api.staging.churchapps.org/{module}

# Example module URLs
https://api.staging.churchapps.org/membership
https://api.staging.churchapps.org/attendance
https://api.staging.churchapps.org/content
https://api.staging.churchapps.org/giving
https://api.staging.churchapps.org/messaging
https://api.staging.churchapps.org/doing

Option 2: Local API

Run the Api project on your machine. Requires MySQL 8.0+ with databases created for each module.

# Base URL pattern
http://localhost:8084/{module}

# Example module URLs
http://localhost:8084/membership
http://localhost:8084/attendance
http://localhost:8084/content
http://localhost:8084/giving
http://localhost:8084/messaging
http://localhost:8084/doing

API Environment Variables

The core Api project (.env.sample) has the most configuration. Here are the key variables:

Shared Settings

VariableDescriptionExample
ENVIRONMENTRuntime environmentdev
SERVER_PORTHTTP port for the local dev server8084
ENCRYPTION_KEY192-bit encryption key for sensitive dataaSecretKeyOfExactly192BitsLength
JWT_SECRETSecret for signing JSON Web Tokensjwt-secret-dev
FILE_STOREWhere to store uploaded files (disk or s3)disk
CORS_ORIGINAllowed CORS origins (* for local dev)*

Database Connections

Each API module has its own MySQL database and connection string:

VariableDatabase
MEMBERSHIP_CONNECTION_STRINGmysql://root:password@localhost:3306/membership
ATTENDANCE_CONNECTION_STRINGmysql://root:password@localhost:3306/attendance
CONTENT_CONNECTION_STRINGmysql://root:password@localhost:3306/content
GIVING_CONNECTION_STRINGmysql://root:password@localhost:3306/giving
MESSAGING_CONNECTION_STRINGmysql://root:password@localhost:3306/messaging
DOING_CONNECTION_STRINGmysql://root:password@localhost:3306/doing
note

Update root:password with your actual MySQL credentials. Each database must be created before running the API. Use npm run initdb to create the schema for all modules, or npm run initdb:membership for a single module.

WebSocket Settings

VariableDescriptionExample
SOCKET_PORTPort for the WebSocket server8087
SOCKET_URLWebSocket URL for clients to connectws://localhost:8087

Web App Environment Variables

B1Admin (React + Vite)

Sample file: .env.sample

VariableDescriptionExample (Staging)
REACT_APP_STAGEEnvironment namedemo
PORTDev server port3101
REACT_APP_MEMBERSHIP_APIMembership API URLhttps://api.staging.churchapps.org/membership
REACT_APP_ATTENDANCE_APIAttendance API URLhttps://api.staging.churchapps.org/attendance
REACT_APP_GIVING_APIGiving API URLhttps://api.staging.churchapps.org/giving
REACT_APP_CONTENT_ROOTContent delivery URLhttps://content.staging.churchapps.org
REACT_APP_GOOGLE_ANALYTICSGoogle Analytics ID (optional)UA-123456789-1

For local API development, uncomment and use the localhost variants:

REACT_APP_MEMBERSHIP_API=http://localhost:8084/membership
REACT_APP_ATTENDANCE_API=http://localhost:8084/attendance
REACT_APP_GIVING_API=http://localhost:8084/giving
REACT_APP_CONTENT_API=http://localhost:8084/content
REACT_APP_DOING_API=http://localhost:8084/doing
REACT_APP_MESSAGING_API=http://localhost:8084/messaging

B1App (Next.js)

Sample file: .env.sample

VariableDescriptionExample (Staging)
NEXT_PUBLIC_MEMBERSHIP_APIMembership API URLhttps://api.staging.churchapps.org/membership
NEXT_PUBLIC_ATTENDANCE_APIAttendance API URLhttps://api.staging.churchapps.org/attendance
NEXT_PUBLIC_GIVING_APIGiving API URLhttps://api.staging.churchapps.org/giving
NEXT_PUBLIC_MESSAGING_APIMessaging API URLhttps://api.staging.churchapps.org/messaging
NEXT_PUBLIC_CONTENT_APIContent API URLhttps://api.staging.churchapps.org/content
NEXT_PUBLIC_CONTENT_ROOTContent delivery URLhttps://staging.churchapps.org/content
NEXT_PUBLIC_CHURCH_APPS_URLChurchApps base URLhttps://staging.churchapps.org
NEXT_PUBLIC_GOOGLE_ANALYTICSGoogle Analytics ID (optional)UA-123456789-1
info

Next.js requires the NEXT_PUBLIC_ prefix for any environment variable that needs to be available in the browser. Server-only variables do not need this prefix.

LessonsApp (Next.js)

Sample file: dotenv.sample.txt

VariableDescriptionExample (Staging)
STAGEEnvironment stagestaging
NEXT_PUBLIC_LESSONS_APILessons API URLhttps://api.staging.lessons.church
NEXT_PUBLIC_CONTENT_ROOTContent delivery URLhttps://api.staging.lessons.church/content
NEXT_PUBLIC_CHURCH_APPS_URLChurchApps base URLhttps://staging.churchapps.org

Mobile App Environment Variables

B1Mobile (React Native / Expo)

Sample file: dotenv.sample.txt

VariableDescriptionExample (Staging)
STAGEEnvironment namedev
MEMBERSHIP_APIMembership API URLhttps://api.staging.churchapps.org/membership
MESSAGING_APIMessaging API URLhttps://api.staging.churchapps.org/messaging
ATTENDANCE_APIAttendance API URLhttps://api.staging.churchapps.org/attendance
GIVING_APIGiving API URLhttps://api.staging.churchapps.org/giving
DOING_APIDoing API URLhttps://api.staging.churchapps.org/doing
CONTENT_APIContent API URLhttps://api.churchapps.org/content
CONTENT_ROOTContent delivery URLhttps://content.staging.churchapps.org
LESSONS_ROOTLessons site URLhttps://staging.lessons.church
tip

Mobile apps do not use the REACT_APP_ or NEXT_PUBLIC_ prefix. Environment variable access is handled by the Expo configuration.


Quick Reference: Sample File Locations

ProjectSample File
Api.env.sample
B1Admin.env.sample
B1App.env.sample
B1Mobiledotenv.sample.txt
B1Checkindotenv.sample.txt
LessonsAppdotenv.sample.txt
AskApidotenv.sample.txt