-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
51 lines (42 loc) · 1.23 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
47
48
49
50
51
// Modules
require('dotenv').config()
const chalk = require('chalk')
const express = require('express')
const cors = require('cors')
const path = require('path')
const cookieParser = require('cookie-parser')
const mongoose = require('mongoose')
const bodyparser = require('body-parser')
const requestLog = require('./routers/request-log')
const Error = require('./middlewares/error')
// Default Variebles
const app = express()
const PORT = process.env.PORT || 5000
// Default Use and Set
app.set('views', path.resolve(__dirname, 'client'))
app.use(cors())
app.use(cookieParser())
app.use(bodyparser.json())
app.use(Error)
app.use('/api/', requestLog)
app.use(bodyparser.urlencoded({ extended: true }))
// Default Promise with function => "start"
let r = new Promise((resolve, reject) => {
let start = async () => {
try {
await mongoose.connect(process.env.DB_URL, {})
app.listen(PORT, () => console.log(chalk.yellow(`Server is working on PORT ${PORT}`)));
} catch (e) {
console.error(e);
process.exit(1)
}
}
resolve(start);
})
.then(data => {
data()
})
.catch(err => {
console.log(chalk.red(`Error: ${chalk.yellow(err)}`));
})
// || \\