-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
38 lines (30 loc) · 927 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
34
35
36
37
38
require('dotenv').config();
const mongoose = require('mongoose');
const express = require('express');
const app = express();
// const swaggerUi = require('swagger-ui-express');
// const swaggerDocument = require('./swagger.json');
// app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument));
// Require routes
const authRoutes = require('./routes/authRoutes');
const postRoutes = require('./routes/postRoutes');
// Connect to DB
mongoose.connect(
process.env.MONGO_REMOTE,
{ useNewUrlParser: true, bufferCommands: false },
(err) => {
if (err) {
throw err;
}
console.log('Connected to DB!');
},
);
// Middlewares
app.use(express.json());
// Routes middlewares
app.use('/api/v1/user', authRoutes);
app.use('/api/v1/posts', postRoutes);
app.set('PORT', process.env.PORT || 3000);
app.listen(app.get('PORT'), () => {
console.log(`Server started on port: ${app.get('PORT')}`);
});