-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
33 lines (27 loc) · 733 Bytes
/
server.js
File metadata and controls
33 lines (27 loc) · 733 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
const express = require('express');
const dotenv = require('dotenv');
const mongoose = require('mongoose');
const authRoutes = require('./routes/authRoutes');
const cors = require('cors');
// Umgebungsvariablen laden
dotenv.config();
const app = express();
// Middleware
app.use(express.json());
app.use(cors());
// MongoDB-Verbindung
mongoose.connect(process.env.MONGO_URI, {
useNewUrlParser: true,
useUnifiedTopology: true
}).then(() => {
console.log('Datenbank verbunden');
}).catch((err) => {
console.error('Datenbankfehler:', err);
});
// Routen
app.use('/api/auth', authRoutes);
// Server starten
const PORT = process.env.PORT || 5000;
app.listen(PORT, () => {
console.log(`Server läuft auf Port ${PORT}`);
});