Skip to content

Commit

Permalink
Refactor server initialization and database connection logic for impr…
Browse files Browse the repository at this point in the history
…oved clarity and error handling
  • Loading branch information
SGOD-pro committed Jan 29, 2025
1 parent 5dbc688 commit 46e414a
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
import { app } from "./app.js";
import {app} from "./app.js";
import ConnectDB from "./db/index.js";
import dotenv from "dotenv";
import dotenv from 'dotenv'
dotenv.config({ path: './.env' })

// Load environment variables
dotenv.config({ path: "./.env" });

// Connect to the database
(async () => {
try {
await ConnectDB();
console.log("Database connected successfully!");
} catch (error) {
console.error(`Database connection error: ${(error as Error).message}`);
process.exit(1); // Exit if the database connection fails
}
})();

// Export the app (this is optional in case you want to reuse it elsewhere)
export { app };
const PORT = 8080;
ConnectDB().then(() => {
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});
}).catch((error) => {
console.error(`Errors: ${(error as Error).message}`);
process.exit(1);
});

0 comments on commit 46e414a

Please sign in to comment.