feat: basic db connection

This commit is contained in:
eneller
2026-03-06 00:52:27 +01:00
parent 4f206d9ad9
commit 599ed86c52
7 changed files with 100 additions and 26 deletions

View File

@@ -2,6 +2,7 @@ import express, { Express, Request, Response } from "express";
import cors from "cors";
import * as dotenv from "dotenv";
import transactionsRouter from './routes/transactions';
import { db, testConnection } from "./db";
dotenv.config();
@@ -17,6 +18,19 @@ app.get("/api/health", (req: Request, res: Response) => {
app.use('/api/transactions', transactionsRouter);
const PORT: number = parseInt(process.env.PORT as string) || 3000;
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
// Start server after DB connection is established
async function startServer() {
await testConnection(); // Test DB connection first
// Sync models (use migrations in production!)
await db.sync({ alter: true }); // Use { force: true } to drop and recreate tables (development only!)
app.listen(PORT, () => {
console.log(`🚀 Backend Server running on http://localhost:${PORT}`);
});
}
startServer().catch((err) => {
console.error('Failed to start server:', err);
process.exit(1);
});