-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmongoPromise.js
60 lines (46 loc) · 1.24 KB
/
mongoPromise.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
55
56
57
58
59
60
const express = require("express");
const app = express();
let sumOfNum = require("./mylib/sum").sumOfNumbers;
let bodyParser = require('body-parser')
app.use(bodyParser.json());
let connectionUrl ="mongodb://localhost:27017/news"
let mongoose =require("mongoose")
let textFile=require("./models/students")
mongoose.connect(connectionUrl,{useNewUrlParser:true})
.then(() => {
console.log("Mongoose connected");
})
.catch((err) => {
console.log("Error while connecting ", err);
});
app.get("/promises",(req,res)=>{
then(() => {
console.log("Mongoose connected");
})
.catch((err) => {
console.log("Error while connecting ", err);
});
})
app.get("/getAllStudents", (req, res) => {
textFile.find().then(data=> {
res.json(data);
}).catch(err=> {
res.send("Could not fetch students")
});
})
app.get("/insert", (req, res) => {
let s1 = {
name: 'Simil',
age: 22,
mark: 88
}
let stud = new textFile(s1);
stud.save().then(()=>{
res.send("Inserted Successfully");
}).catch(()=>{
res.send("something wrong")
});
});
app.listen(4343,()=>{
console.log("working")
})