-
Notifications
You must be signed in to change notification settings - Fork 0
/
Server.js
38 lines (34 loc) · 934 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
33
34
35
36
37
38
const http = require('http');
const App = require('./App');
const dotenv = require('dotenv');
const mongoose = require('mongoose');
const server = http.createServer(App);
dotenv.config({ path: './config.env' });
const { getPlanets } = require('./src/models/planets_Models/planets');
const {
loadSpaceLaunchData,
} = require('./src/models/launches_Models/launches');
const db = process.env.DATABASE.replace(
'<PASSWORD>',
process.env.DATABASE_PASSWORD
);
async function connectDB() {
await mongoose
.connect(db)
.then((res) => {
console.log('Database connected successfully');
})
.catch((err) => {
console.log(err.message);
});
}
const port = process.env.PORT1 || process.env.PORT2;
async function startServer(db) {
await connectDB();
await getPlanets();
await loadSpaceLaunchData();
server.listen(port, () => {
console.log(`App running on port ${port}`);
});
}
startServer();