-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
43 lines (32 loc) · 1.05 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
let express = require('express');
let app = express();
app.use(express.json());
let incomeTracker = [];
const { Database } = require("quickmongo");
const db = new Database("mongodb+srv://Week7:[email protected]/?retryWrites=true&w=majority");
db.on("ready", () => {
console.log("Connected to the database");
});
db.connect();
app.use('/',express.static('public'));
app.post('/Income',(req,res)=>{
console.log(req.body);
let currentDate = new Date();
let options = { weekday: 'short', month: 'short', day: 'numeric', year: 'numeric' };
let formattedDate = currentDate.toLocaleDateString('en-US', options);
let obj = {
Date: formattedDate,
Income: req.body.Income
};
db.push("incomeTracker",obj);
res.json({task:"sucess"});
})
app.get('/History',(req,res)=>{
db.get("incomeTracker").then(incomeData =>{
let obj = {data: incomeData};
res.json(obj);
})
})
app.listen(5000,()=>{
console.log('listening to localhost:5000');
})