-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
38 lines (28 loc) · 989 Bytes
/
server.js
File metadata and controls
38 lines (28 loc) · 989 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
34
35
36
37
require('dotenv').config()
const express = require('express');
const rateLimit = require('express-rate-limit');
const cors = require('cors');
const router = require('./router/index')
const sequelize = require('./config/database')
const app = express()
const port = process.env.PORT || 3000
const limiter = rateLimit({
windowMs: 15 * 60 * 1000, // 15 minutes
max: 100, // limit each IP to 100 requests per windowMs
message: 'Too many requests from this IP, please try again after 15 minutes'
})
app.use(express.json());
app.use(cors());
app.use('/api', router, limiter)
const startServer = async () => {
try {
await sequelize.authenticate()
console.log('Connection to the database has been established successfully.');
app.listen(port, () => {
console.log(`Server is running on http://localhost:${port}`)
});
} catch (error) {
console.log('Unable to connect to the database:', error);
}
}
startServer();