-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
47 lines (40 loc) · 987 Bytes
/
server.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
const express=require(`express`);
const { default: mongoose } = require("mongoose");
const mongppse=require(`mongoose`);
const path=require(`path`);
const port = 3021
const app=express();
app.use(express.static(__dirname));
app.use(express.urlencoded({extended:true}))
mongoose.connect('mongodb://127.0.0.1:27017/students')
const db=mongoose.connection
db.once('open',()=>{
console.log("Mongodb connection sucessfull")
})
const userSchema=new mongoose.Schema({
regd_no:String,
name:String,
email:String,
branch:String
})
const Users=mongoose.model("data", userSchema)
app.get('/',(req, res)=>
{
res.sendFile(path.join(__dirname,'form.html'))
})
app.post('/post',async(req,res)=>{
const { regd_no,name,email,branch}=req.body
const user= new Users({
regd_no,
name ,
email,
branch
})
await user.save()
console.log(user)
res.send("Form Submission Suessfully!")
})
app.listen(port,()=>
{
console.log("server started")
})