Skip to content

add fallback environment variables for database and port#66

Open
lover3123 wants to merge 1 commit into
Sitaram8472:mainfrom
lover3123:main
Open

add fallback environment variables for database and port#66
lover3123 wants to merge 1 commit into
Sitaram8472:mainfrom
lover3123:main

Conversation

@lover3123

Copy link
Copy Markdown

Description

Currently, the backend/server.js file relies strictly on a local .env file for configuration. If this file is missing (e.g., during new developer onboarding or in fresh cloud deployments), the application throws an unhandled extraction exception and crashes.

This PR introduces reliable, safe fallback bindings using short-circuit operators (||) to ensure the server can boot cleanly even without an explicit .env file.

Changes Made

  • Updated backend/server.js to include fallback defaults for PORT and MONGO_URL.
  • Refactored the mongoose.connect() function to utilize the securely defined MONGO_URL variable.
  • Ensured the app.listen() block dynamically uses the resolved PORT.

Testing Instructions

Verified the fallback behavior locally:

  1. Temporarily renamed .env to .env.backup.
  2. Started the development server.
  3. Confirmed the server successfully defaulted to port 5000 and connected to mongodb://127.0.0.1:27017/school_website without throwing undefined variable errors.

Related Issues

Fixes #28

Checklist

  • I have tested these changes locally.
  • I have read and followed the Contributing.md guidelines.
  • My code follows the existing style and conventions of the project.

@Sitaram8472

Copy link
Copy Markdown
Owner

solve merge conflicts @lover3123

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Enhancement]: Implement safe environment variables fallback configuration in backend

2 participants