Skip to content

Commit 469e3df

Browse files
committed
app.js func fix
1 parent 46e01f3 commit 469e3df

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

app.js

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,8 @@ if (!devMode) {
3838

3939
async function start() {
4040
try {
41-
if (mongoUri) {
42-
await mongoose.connect(mongoUri, {
43-
useNewUrlParser: true,
44-
useUnifiedTopology: true,
45-
useCreateIndex: true
46-
})
47-
} else {
48-
console.log("\n!!!NO MONGO URI!!!")
49-
}
50-
app.listen(PORT, () => logServerStart(PORT))
41+
connectMongo(mongoUri)
42+
app.listen(PORT, logServerStart)
5143
} catch (e) {
5244
console.log('Server Error', e.message)
5345
process.exit(1)
@@ -56,12 +48,25 @@ async function start() {
5648

5749
start()
5850

59-
function logServerStart(PORT) {
60-
dns.lookup(os.hostname(), (err, address, fam) => {
61-
const [logN, bef, af] = devMode ? ['Express server', ' ', ':'] : ['React Notes App', '-', '']
62-
console.log(`\n${logN} has been started`)
63-
console.log(`${bef} Local${af} http://localhost:${PORT}`)
64-
console.log(`${bef} On Your Network${af} http://${address}:${PORT}`)
51+
async function connectMongo(mongoUri) {
52+
if (mongoUri) {
53+
await mongoose.connect(mongoUri, {
54+
useNewUrlParser: true,
55+
useUnifiedTopology: true,
56+
useCreateIndex: true
57+
})
58+
} else {
59+
console.log("\n!!!NO MONGO URI!!!")
60+
}
61+
}
62+
63+
function logServerStart() {
64+
dns.lookup(os.hostname(), (err, address) => {
65+
const [logName, sBef, sAft] = devMode ? ['Express server', ' ', ':'] : ['React Notes App', '-', '']
66+
console.log(`\n${logName} has been started`)
67+
console.log(`${sBef} Local${sAft} http://localhost:${PORT}`)
68+
console.log(`${sBef} On Your Network${sAft} http://${address}:${PORT}`)
69+
if (err) console.log(err)
6570
})
6671
}
6772

0 commit comments

Comments
 (0)