Skip to main content

Overview

CEMAC uses environment variables to configure Firebase integration and server settings. These variables must be set before running the application in both development and production environments.

Required Variables

Never commit your .env file to version control. Always keep your Firebase credentials secure and use environment-specific values.

Server Configuration

PORT
number
default:"3000"
The port number on which the CEMAC server will listen for incoming requests.Example: 3000

Firebase Configuration

CEMAC integrates with Firebase for authentication and database services. The following variables are required to connect to your Firebase project:
FIREBASE_API_KEY
string
required
Your Firebase project’s API key. This is used to authenticate requests to Firebase services.Location: Firebase Console > Project Settings > General > Your apps > Web appExample: AIzaSyC1234567890abcdefghijklmnopqrstuv
FIREBASE_AUTH_DOMAIN
string
required
The authentication domain for your Firebase project.Format: {project-id}.firebaseapp.comExample: cemac-prod.firebaseapp.com
FIREBASE_PROJECT_ID
string
required
Your Firebase project’s unique identifier.Location: Firebase Console > Project Settings > General > Project IDExample: cemac-prod
FIREBASE_STORAGE_BUCKET
string
required
The Cloud Storage bucket for your Firebase project.Format: {project-id}.appspot.comExample: cemac-prod.appspot.com
FIREBASE_MESSAGING_SENDER_ID
string
required
The sender ID for Firebase Cloud Messaging.Location: Firebase Console > Project Settings > Cloud Messaging > Sender IDExample: 123456789012
FIREBASE_APP_ID
string
required
Your Firebase web app’s unique identifier.Location: Firebase Console > Project Settings > General > Your apps > App IDExample: 1:123456789012:web:abcdef1234567890

Setup Instructions

1

Create .env file

Create a .env file in the root directory of your project:
touch .env
2

Add environment variables

Copy the following template and replace the placeholder values with your actual Firebase credentials:
PORT=3000
FIREBASE_API_KEY=your_api_key
FIREBASE_AUTH_DOMAIN=your_auth_domain
FIREBASE_PROJECT_ID=your_project_id
FIREBASE_STORAGE_BUCKET=your_storage_bucket
FIREBASE_MESSAGING_SENDER_ID=your_messaging_sender_id
FIREBASE_APP_ID=your_app_id
3

Verify configuration

Ensure the .env file is listed in your .gitignore to prevent accidental commits:
cat .gitignore | grep .env
If not present, add it:
echo ".env" >> .gitignore
4

Test the configuration

Start the development server to verify the environment variables are loaded correctly:
npm run dev
The server should start without errors and display:
🚀 Servidor CEMAC corriendo en: http://localhost:3000

Production Environment

For production deployments (e.g., Vercel), set environment variables through your hosting platform’s dashboard:
1

Access environment settings

Navigate to your project settings in your hosting platform.
2

Add variables

Add each environment variable as a key-value pair. Ensure you select the appropriate environment (Production, Preview, Development).
3

Redeploy

Trigger a new deployment to apply the environment variables.
Use different Firebase projects for development and production to prevent data conflicts and ensure security isolation.

Validation

You can verify your environment configuration by checking the server logs when the application starts:
npm start
Look for successful initialization messages. If Firebase credentials are incorrect, you’ll see authentication errors in the console.

Troubleshooting

Server won’t start

  • Verify all required variables are set in .env
  • Check for typos in variable names (they are case-sensitive)
  • Ensure no extra spaces around = signs in .env

Firebase authentication fails

  • Verify your Firebase API key is correct
  • Check that your Firebase project is active
  • Ensure the auth domain matches your Firebase project

Port already in use

  • Change the PORT value to an available port
  • Or stop the process using the current port:
    lsof -ti:3000 | xargs kill
    

Build docs developers (and LLMs) love