-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
33 lines (28 loc) · 936 Bytes
/
index.js
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 mongoose = require('mongoose');
const dotenv = require('dotenv');
const authRoutes = require('./routes/authRoutes');
const poemRoutes = require('./routes/poemRoutes');
const cors = require('cors');
const userActionsRoutes = require("./routes/userActionsRoutes");
dotenv.config();
const app = express();
const PORT = process.env.PORT || 3000;
const MONGODB_URI = process.env.MONGODB_URI || 'mongodb://localhost:27017/crudapi';
mongoose.connect(MONGODB_URI, {
useNewUrlParser: true,
useUnifiedTopology: true,
}).then(() => {
console.log('Connected to MongoDB');
}).catch(err => {
console.error('Error connecting to MongoDB:', err.message);
process.exit(1);
});
app.use(express.json());
app.use(cors());
app.use('/auth', authRoutes);
app.use('/api', poemRoutes);
app.use('/api', userActionsRoutes);
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});