-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
45 lines (37 loc) · 1.01 KB
/
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
34
35
36
37
38
39
40
41
42
43
44
45
const express = require('express');
const app = express();
const mongoose = require('mongoose');
const cors = require('cors');
const bodyParser = require('body-parser');
require('dotenv/config');
//import routes
const authRoute = require('./routes/auth');
const updateRoute = require('./routes/update');
const getStatRoute = require('./routes/getStat');
//middlewares
app.use(cors());
app.use(bodyParser.json());
app.use(express.json());
// routes
app.get('/', (req, res) => {
res.send('we are on home');
});
mongoose.connect(process.env.DB_CONNECT, {
useNewUrlParser: true,
useUnifiedTopology: true,
});
const db = mongoose.connection;
db.once('open', _ => {
console.log('Database connected:', process.env.DB_CONNECT);
});
db.on('error', err => {
console.error('connection error:', err);
});
//route middlewares
app.use('/auth', authRoute);
app.use('/update', updateRoute);
app.use('/getstat', getStatRoute);
//listening
app.listen(process.env.PORT || 5000, () => {
console.log('server is listenning on port');
});