-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
46 lines (39 loc) · 1.05 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
46
const express = require('express');
const morgan = require('morgan');
const cors = require('cors');
const mongoose = require('mongoose');
const dotenv = require('dotenv');
// Route Dependencies
const authRouter = require('./routes/auth.route');
const adminRouter = require('./routes/admin.route');
const userRouter = require('./routes/user.route');
const defaultRouter = require('./routes/default.route');
// Init
const app = express();
dotenv.config();
// Choose a port to listen to.
const PORT = process.env.PORT || 3001;
// Middlewares
app.use(cors());
app.use(express.json());
app.use(morgan('dev'));
// Connect to MongoDB Database
mongoose.connect(process.env.MONGODB_URL, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(res => {
console.log('Connected to ' + res.connection.host);
})
.catch(e => {
console.log(e);
})
// Routes
app.use('/auth', authRouter);
app.use('/admin', adminRouter);
app.use('/user', userRouter);
app.use('/', defaultRouter);
// Listen on a port
app.listen(PORT, () => {
console.log('Listening on ' + PORT);
})