Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Directory Reorganization and Minor Fixes #707

Closed
wants to merge 16 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
npm initialised backend
ThePhoenix08 committed Jan 3, 2025

Verified

This commit was signed with the committer’s verified signature.
r0adkll Drew Heavner
commit ab8156e9eb0e2c909d174904e0f32fe1e67b68f9
9 changes: 9 additions & 0 deletions backend/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const CONSTANTS = {
PORT: process.env.PORT || 5000,
ORIGIN_URL: process.env.ORIGIN_URL || 'http://localhost:3000',
MONGODB_URL: process.env.MONGODB_URL || 'mongodb://localhost:27017/devdisplay',
JSON_LIMIT: '50mb',
ENV: process.env.NODE_ENV || 'development',
};

export default CONSTANTS;
18 changes: 18 additions & 0 deletions backend/database/connectToDatabase.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import mongoose from 'mongoose';
import CONSTANTS from '../constants.js';

async function connectToDatabase() {
try {
const uri = CONSTANTS.MONGODB_URL;
const { connection } = await mongoose.connect(uri);
if(CONSTANTS.ENV === 'development') {
console.log(`🗄️ Connected to: ${uri}`);
}
console.info(`⚙️ MongoDB connected, DB HOST: ${connection.host}`);
} catch (error) {
console.error("⚠️ Error connecting to the database:", error);
process.exit(1);
}
}

export default connectToDatabase;
Loading