-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
55 lines (44 loc) · 1.31 KB
/
index.js
File metadata and controls
55 lines (44 loc) · 1.31 KB
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
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
}))
const url = "mongodb+srv://admin:q7NYWoDAe163q3vb@cluster0.71ngi.mongodb.net/myFirstDatabase?retryWrites=true&w=majority"
mongoose.connect(url,{
useNewUrlParser: true,
useUnifiedTopology: true
});
var db = mongoose.connection;
db.on('error',()=>console.log("Error in Connecting to Database"));
db.once('open',()=>console.log("Connected to Database"))
app.post("/sign_up",(req,res)=>{
var name = req.body.name;
var email = req.body.email;
var yearOfGrad = req.body.phno;
var interest = req.body.cars;
var data = {
"name": name,
"email" : email,
"year": yearOfGrad,
"intrest" : interest
}
db.collection('newsdbs').insertOne(data,(err,collection)=>{
if(err){
throw err;
}
console.log("Record Inserted Successfully");
return res.redirect('f.html');
});
})
var PORT = process.env.PORT || 5000;
app.get("/",(req,res)=>{
res.set({
"Allow-access-Allow-Origin": '*'
})
return res.redirect('index.html');
}).listen(PORT);
console.log(`Listening on PORT ${PORT}`);