-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
44 lines (38 loc) · 1.17 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
var express = require("express")
var bodyParser = require("body-parser")
var mongoose = require("mongoose")
const app= express()
app.use(bodyParser.json())
app.use(express.static('public'))
app.use(bodyParser.urlencoded({
extended: true
}))
mongoose.connect('mongodb://localhost:27017/MoneyList')
var db = mongoose.connection
db.on('error', ()=> console.log("Error in connecting to the Database"))
db.once('open', () => console.log("Connected to Database"))
app.post("/add", (req,res) =>{
var category_select = req.body.category_select
var amount_input= req.body.amount_input
var info = req.body.info
var date_input = req.body.date_input
var data={
"Category": category_select,
"Amount" : amount_input,
"Info": info,
"Date": date_input
}
db.collection('users').insertOne(data, (err,collection) => {
if(err){
throw err;
}
console.log("Record Inserted Successfully")
})
})
app.get("/",(req,res) =>{
res.set({
"Allow-access-Allow-Origin":'*'
})
return res.redirect('index.html')
}).listen(5000)
console.log("Listening on port 5000")