-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
96 lines (85 loc) · 2.45 KB
/
app.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
var express=require("express");
var app=express();
var bodyParser=require("body-parser");
app.use(bodyParser.urlencoded({extended:true}));
var mongoose=require("mongoose");
// ---->
// var MongoClient = require('mongodb').MongoClient,
// f = require('util').format,
// assert = require('assert');
// var user = encodeURIComponent('humaid');
// var password = encodeURIComponent('abc123');
// var authMechanism = 'DEFAULT';
// // Connection URL
// var url = f('mongodb://localhost:27017/TestSoftware',
// user, password, authMechanism);
// // Use connect method to connect to the Server
// MongoClient.connect(url, function(err, db) {
// assert.equal(null, err);
// console.log("Connected correctly to server");
// db.close();
// });
// --->
mongoose.connect("mongodb://localhost:27017/TestSoftware",{useNewUrlParser:true});
//app.use(express.static(__dirname+"/public"));
mongoose.set('useNewUrlParser', true);
mongoose.set('useFindAndModify', false);
mongoose.set('useCreateIndex', true);
mongoose.set('useUnifiedTopology', true);
app.set("view engine","ejs");
var studentSchema = mongoose.Schema({
rollno: String,
marksscored : String,
name : String,
email : String
});
var Student = mongoose.model("Student",studentSchema);
// var data={
// name:"Haris",
// rollno:"cs180501053",
// marksscored:"0"
// }
// Student.create(data,function(err,Student){
// if(err){
// console.log(err);
// }else{
// console.log("Successfully created");
// }
// })
var rollno;
var name;
var marksscored;
app.post("/dispcscmarks",function(req,res){
marksscored = req.body.marks;
console.log(marksscored);
// console.log(name);
// console.log(rollno);
Student.findOneAndUpdate({rollno:rollno},{marksscored:marksscored},function(err,student){
if(err){
console.log(err);
}else{
console.log("Updated in database");
}
})
})
app.get("/csclogin",function(req,res){
res.render("csclogin");
});
app.get("/",function(req,res){
res.render("index");
});
app.post("/cscchecklogin",function(req,res){
rollno = req.body.rollno;
name = req.body.name;
email = req.body.email;
Student.create({rollno:rollno,name:name,email:email,marksscored:'0'},function(err,student){
if(err){
console.log(err);
}else{
res.render("demo",{Student:student})
}
})
})
app.listen(3000,function(){
console.log("Server has started");
});