-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver3.js
51 lines (41 loc) · 1.31 KB
/
server3.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
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://0.0.0.0:27017/Database3')
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) => {
// Extract data from the request body
var name = req.body.name;
var email = req.body.email;
var password = req.body.password;
// Create an object to hold the data
var data = {
"name": name,
"email": email,
"password": password
};
// Insert the data into the 'users' collection
db.collection('users').insertOne(data, (err, collection) => {
if(err){
throw err;
}
console.log("Record Inserted Successfully");
// Redirect to the login page after successful signup
return res.redirect('login3.html');
});
});
app.get("/",(req,res) => {
res.set({
"Allow-acces-Allow-Origin":'*'
})
return res.redirect('login3.html')
}).listen(3003);
console.log("Listening on port 3003")