-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
91 lines (69 loc) · 2.47 KB
/
app.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import * as dotenv from 'dotenv' // see https://github.com/motdotla/dotenv#how-do-i-use-dotenv-with-import
dotenv.config()
import express from 'express'
import mongoose from 'mongoose';
const app = express();
const PORT = process.env.PORT || 3000;
import cors from 'cors'
app.use(cors())
// mondodb connect
mongoose
.connect(
process.env.MONGODB_URI,
{ useNewUrlParser: true, useUnifiedTopology: true }
)
.then(() => console.log("MongoDB connected"))
.catch(err => console.log(err));
const userSchema = new mongoose.Schema({});
const a = [];
const Buildings = mongoose.model('Hello', userSchema, 'buildings');
const Entrances = mongoose.model('Hi', userSchema, 'entrances');
const ShuttleStops = mongoose.model('Hey', userSchema, 'shuttle-stops');
const Events = mongoose.model('Wassup', userSchema, 'events');
//const Entrances = mongoose.model('test', userSchema);
//const ShuttleStops = mongoose.model('test', userSchema);
app.get('/', (req, res) => {
Buildings.find({}, (err, found) => {
if (!err) {
a[0] = found;
//res.send(found);
} else {
console.log(err);
res.send("Some error occured!")
}
}).clone().catch(err => console.log("Error occured, " + err));
Entrances.find({}, (err, found) => {
if (!err) {
a[1] = found;
//res.send(found);
} else {
console.log(err);
res.send("Some error occured!")
}
}).clone().catch(err => console.log("Error occured, " + err));
ShuttleStops.find({}, (err, found) => {
if (!err) {
a[2] = found;
} else {
console.log(err);
res.send("Some error occured!")
}
}).clone().catch(err => console.log("Error occured, " + err));
Events.find({}, (err, found) => {
if (!err) {
a[3] = found;
console.log(a);
res.send(a);
} else {
console.log(err);
res.send("Some error occured!")
}
}).clone().catch(err => console.log("Error occured, " + err));
});
//const Buildings = mongoose.model('test.buildings', userSchema);
//const Entrances = mongoose.model('test.entrances', userSchema);
//const ShuttleStops = mongoose.model('test.shuttle-stops', userSchema);
// get documents
// Server listen
//app.listen(3000, () => console.log(`Server listening to port 3000`));
app.listen(PORT, () => console.log(`Server listening to port ${PORT}`));