-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
32 lines (30 loc) · 896 Bytes
/
server.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
const express = require('express')
const fs = require('fs')
const prompt = require('prompt-sync')()
const path = require('path')
const startServer = function () {
const servelet = require('./app')
let { serverPort } = require('./config/db_config')
const app = express()
app.use(servelet.init())
serverPort = serverPort || 5000
app.listen(serverPort, err => {
if (err) console.log(err)
else console.log('server running on port ' + serverPort)
})
}
if (!fs.existsSync(path.join(__dirname, 'config', 'db_config.js'))) {
const ans = prompt('No configuration file found. Generate?(y|N): ')
if (ans === 'y') {
const configure = require('./configure')
configure((err) => {
if (err) throw err
else startServer()
})
} else {
console.error('Cannot proceed without configuration file. Aborting...')
process.exit()
}
} else {
startServer()
}