-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
54 lines (42 loc) · 1.11 KB
/
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import express from "express";
import mongoose from "mongoose";
import Cards from './dbCards.js';
import Cors from 'cors';
//App config
const app=express()
const port=process.env.PORT || 8001
// middlewares
app.use(express.json());
app.use(Cors());
// DB config
// admin12345
const uri ="mongodb+srv://admin:[email protected]/?retryWrites=true&w=majority";
mongoose.connect(uri,{
useNewUrlParser:true,
useUnifiedTopology:true,
});
// API endpoints
app.get("/",(req,res)=>res.status(200).send("Hello World"))
app.post("/tinder/cards", (req, res) => {
// Trying for getting the cards'
const dbCard=req.body;
Cards.create(dbCard,(err, data) => {
if (err) {
res.status(500).json({ err: err.message });
} else {
res.status(201).json(data);
}
});
});
app.get("/tinder/cards", (req, res) => {
// Trying for getting the cards
Cards.find((err,data)=>{
if(err){
res.status(500).json({ err: err.message });
}else{
res.status(200).send(data);
}
})
})
// Listner
app.listen(port, () => console.log(`listening on port${port}`));