-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
36 lines (29 loc) · 912 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
const app = require('./app');
const mongoose = require('mongoose');
const dotenv = require('dotenv');
dotenv.config({ path: './config.env' });
// mongoose.connect(process.env.DATABASEURL).then(()=>{
// console.log("DATABASE Connected");
// }).catch((e)=>{
// console.log('DATABASE Not Connected' + e.message);
// })
// const port = process.env.PORT || 8080;
const PORT = process.env.PORT || 8080
const connectDB = async () => {
try {
const conn = await mongoose.connect(process.env.DATABASEURL);
console.log(`MongoDB Connected: ${conn.connection.host}`);
} catch (error) {
console.log(error);
process.exit(1);
}
}
// app.listen(port,()=>{
// console.log("Server is Running on " + port);
// });
//Connect to the database before listening
connectDB().then(() => {
app.listen(PORT, () => {
console.log("listening for requests");
})
})