-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
44 lines (37 loc) · 935 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
37
38
39
40
41
42
43
44
const mongoose = require("mongoose");
const express = require("express");
const app = express();
app.use(express.json());
mongoose
.connect("mongodb://localhost/covid", {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => {
console.log("connected !");
})
.catch((err) => console.log("could not connect"));
const Db = mongoose.model(
"covid19",
new mongoose.Schema({
State: String,
Confirmed: Number,
Recovered: Number,
Deaths: Number,
Active: Number
})
);
app.get("/api/allcases/", async (req, res) => {
const found = await Db.find();
res.send(found);
console.log('found');
});
app.get("/api/allcases/:name", async (req, res) => {
const state = req.params.name;
const data = await Db.find({ State: { $eq: state } });
res.send(data);
});
const port = process.env.PORT || 3000;
app.listen(port, () => {
console.log(`listening on port ${port}`);
});