-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
46 lines (37 loc) · 1 KB
/
index.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
import express from "express";
import path from 'path'
const app=express();
const port=3000
import dbConn from './connection/dbConn.js'
dbConn().then(()=>{
console.log("Connected to the database");
}).catch((err)=>{
console.log("Error connecting to the database",err);
});
//Schema for the database
// import User from './models/user.js'
import bookingSchema from './models/Bookings.js'
app.use(express.static('public'))
app.set('view engine', 'ejs');
app.set('views', path.join('views'))
app.use(express.urlencoded({ extended: true}))
app.get('/',(req,res)=>{
res.render('index')
})
app.get('/thank',(req,res)=>{
res.render('thank')
})
app.post('/submit',(req,res)=>{
const data=req.body;
const booking=new bookingSchema(data);
booking.save().then(()=>{
console.log("Data saved");
}).catch((err)=>{
console.log("Error saving data",err);
})
res.redirect('/thank')
console.log(data);
})
app.listen(port,()=>{
console.log("Server running in port",port);
})