-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
32 lines (24 loc) · 837 Bytes
/
Copy pathindex.js
File metadata and controls
32 lines (24 loc) · 837 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
const express = require('express');
const mongoose = require('mongoose');
const cors = require('cors');
const app = express();
const PORT = 3000;
// Подключение к MongoDB
mongoose.connect('mongodb://localhost:27017/express-backend', {
serverSelectionTimeoutMS: 5000, // Timeout after 5s instead of 30s
}).then(() => console.log('MongoDB connected'))
.catch(err => console.error('MongoDB connection error:', err));
app.use(cors());
app.use(express.json());
app.use(express.static('public'));
// Роуты
const authRoutes = require('./routes/auth');
const postRoutes = require('./routes/posts');
app.use('/auth', authRoutes);
app.use('/posts', postRoutes);
app.get('/', (req, res) => {
res.send('Сервер работает');
});
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
});