Pre-checks
Issue Type
Platform Error (crash, freeze)
Environment
Local Development
Version / Commit ID
main (HEAD)
OS
macOS
Browser (if UI-related)
N/A
Current Behavior
When starting the backend (server.js), the process runs a Cloudinary smoke test and attempts to connect to MongoDB. In the current run, Cloudinary config prints as set but the server fails to connect to MongoDB with an invalid or missing MONGODB_URI. This causes the process to exit and the application never starts.
Expected Behavior
- Backend should clearly report a configuration error for
MONGODB_URI but should not crash in a way that prevents helpful debugging logs.
- Preferably:
- Startup should fail fast with a clear, handled error if required variables are missing (and documentation should reflect required vs optional).
- Or allow startup to continue with reduced functionality if Cloudinary is optional (configurable by
REQUIRE_CLOUDINARY), while failing fast for required dependencies like MongoDB.
- Error messages should suggest remediation steps (e.g., copy .env.example and fill
MONGODB_URI).
Steps to Reproduce
1. From repository root:
cd certinova-backend
# Ensure Cloudinary vars may or may not be set; for this bug, ensure MONGODB_URI is missing or malformed
unset MONGODB_URI
npm run dev
2. Observe that Cloudinary test runs and then Node process exits with the MongoDB "Invalid scheme" error.
Alternative reproducible case (malformed URI):
export MONGODB_URI="not-a-mongo-uri"
npm run dev
Screenshots / Recordings
Logs/Errors
> certinova-backend@1.0.0 dev
> nodemon server.js
[nodemon] 3.1.10
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,cjs,json
[nodemon] starting `node server.js`
=== Cloudinary Configuration Test ===
Environment Variables:
Cloud Name: ✓ Set (your-cloudinary-cloud-name)
API Key: ✓ Set
API Secret: ✓ Set
✅ Cloudinary environment variables are set correctly!
==========================================
Error: Invalid scheme, expected connection string to start with "mongodb://" or "mongodb+srv://"
[nodemon] app crashed - waiting for file changes before starting...
Possible Solution (Optional)
Short-term fixes:
- Validate
MONGODB_URI early and provide a clear, descriptive error message before attempting to connect.
- Wrap
testCloudinaryConfig() and connectDB() startup calls in safe error handling so logs are clear and the application exit is controlled:
- Example in server.js:
try {
await testCloudinaryConfig();
} catch (err) {
console.warn('Cloudinary config test failed:', err.message);
// continue or exit depending on REQUIRE_CLOUDINARY
}
try {
await connectDB();
} catch (err) {
console.error('MongoDB connection failed:', err.message);
process.exit(1);
}
- Add an env flag
REQUIRE_CLOUDINARY (default false) to allow optional Cloudinary in dev.
- Improve documentation to state the required env vars for local/dev runs and provide example
MONGODB_URI values (local and Atlas, redacted).
Medium-term fixes:
- Add integration/startup tests that assert controlled behavior when env vars are missing or malformed.
- Add a helpful health-check endpoint and/or a startup self-check script that returns a structured JSON explaining which dependencies are healthy/unhealthy.
Code of Conduct
Pre-checks
Issue Type
Platform Error (crash, freeze)
Environment
Local Development
Version / Commit ID
main (HEAD)
OS
macOS
Browser (if UI-related)
N/A
Current Behavior
When starting the backend (server.js), the process runs a Cloudinary smoke test and attempts to connect to MongoDB. In the current run, Cloudinary config prints as set but the server fails to connect to MongoDB with an invalid or missing
MONGODB_URI. This causes the process to exit and the application never starts.Expected Behavior
MONGODB_URIbut should not crash in a way that prevents helpful debugging logs.REQUIRE_CLOUDINARY), while failing fast for required dependencies like MongoDB.MONGODB_URI).Steps to Reproduce
Screenshots / Recordings
Logs/Errors
Possible Solution (Optional)
Short-term fixes:
MONGODB_URIearly and provide a clear, descriptive error message before attempting to connect.testCloudinaryConfig()andconnectDB()startup calls in safe error handling so logs are clear and the application exit is controlled:REQUIRE_CLOUDINARY(defaultfalse) to allow optional Cloudinary in dev.MONGODB_URIvalues (local and Atlas, redacted).Medium-term fixes:
Code of Conduct