-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
54 lines (39 loc) · 1.22 KB
/
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
45
46
47
48
49
50
51
52
53
54
let express = require('express');
let app = express();
const { TextEncoder } = require('util');
global.TextEncoder = TextEncoder;
const { TextDecoder } = require('util');
global.TextDecoder = TextDecoder;
app.use(express.json());
app.use(express.json({ limit: '10mb' }));
app.use(express.urlencoded({ limit: '10mb', extended: true }));
let pTracker = [];
//Connect to the mongo DB
const { Database } = require("quickmongo");
const db = new Database("mongodb+srv://project2:[email protected]/?retryWrites=true&w=majority");
db.on("ready", () => {
console.log("Connected to the database");
});
db.connect();
app.use('/', express.static('public'));
////////////////////////////
app.post('/Detail',(req,res)=>{
console.log(req.body);
let obj = {
Img:req.body.img,
Name: req.body.name,
Title: req.body.title
};
db.push("pTracker",obj);
res.json({task:"sucess"});
});
app.get('/CheckDetail',(req,res)=>{
db.get("pTracker").then(pData =>{
let obj = {data: pData};
res.json(obj);
})
});
////////////////////////////////
app.listen(5000, ()=> {
console.log('listening at localhost:5000');
})