File size: 934 Bytes
4bf0aa2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
04fd18e
 
 
4bf0aa2
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

import { app } from './app';
import dotenv from 'dotenv';
import mongoose from 'mongoose';

// Import models to ensure they are registered
import './models/PlatformConnection.model';
import './models/Bill.model';

dotenv.config();
dotenv.config({ path: '.env.local' });

const MONGODB_URI = process.env.MONGODB_URI || 'mongodb://localhost:27017/smartspend';

// Connect to MongoDB
mongoose.connect(MONGODB_URI)
    .then(() => {
        console.log('✅ MongoDB connected successfully');
        console.log(`📊 Database: ${MONGODB_URI}`);
    })
    .catch((error) => {
        console.error('❌ MongoDB connection error:', error.message);
        console.log('⚠️  Server will continue without MongoDB. Platform connections will not work.');
    });

const PORT = Number(process.env.PORT) || 7860;
app.listen(PORT, '0.0.0.0', () => {
    console.log(`🚀 Server running on port ${PORT} (0.0.0.0)`);
});

export default app;