-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
33 lines (26 loc) · 841 Bytes
/
app.js
File metadata and controls
33 lines (26 loc) · 841 Bytes
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
33
import express from 'express';
import cors from 'cors';
import userRoutes from './routes/users.js';
import eventRoutes from './routes/events.js';
import { initializeDatabase } from './initDb.js';
import dotenv from 'dotenv';
// Only load environment variables if .env file exists and not in production or CI environment
if (process.env.NODE_ENV !== 'production' && !process.env.CI) {
dotenv.config();
}
// Initialize Express app
const app = express();
// Define port
const PORT = process.env.PORT || 3000;
// Middleware
app.use(cors());
app.use(express.json());
app.use('/images', express.static('public/images')); // Serve uploaded images
// Routes
app.use('/users', userRoutes);
app.use('/user', eventRoutes);
// Start server
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
initializeDatabase();
});