forked from theabhishekgoyal/WellHealth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
59 lines (55 loc) · 1.64 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
47
48
49
50
51
52
53
54
55
56
57
58
59
const express = require("express");
const bodyParser = require("body-parser");
const mongoose = require("mongoose");
require('dotenv').config();
const PORT = process.env.PORT ||3000
const mongoos_key = process.env.MONGOOSE_KEY;
const app = express();
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.static(__dirname+"/public"));
// Using mongodb atlas cloud database
mongoose
.connect(
mongoos_key
)
.then(() => console.log("Connected to MongoDB Database"))
.catch((err) => console.log(err));
const appformSchema = new mongoose.Schema({
department: String,
email:String,
date: String,
time: String,
name: String,
phone: String,
message: String,
});
const appform = new mongoose.model("appform", appformSchema);
app.get("/", function (req, res) {
res.sendFile(__dirname + "/index.html");
});
app.get("/appointment", function (req, res) {
res.sendFile(__dirname + "/public/appoinment.html");
});
app.post("/appointment", function (req, res) {
const createappointment = async () => {
try {
const newdata = new appform({
department: req.body.department,
date: req.body.date,
name:req.body.name,
time:req.body.time,
message:req.body.message,
phone:req.body.phone,
email:req.body.email,
});
const result = await newdata.save();
} catch (err) {
console.log(err);
}
};
createappointment();
res.sendFile(__dirname + "/public/confirmation.html");
});
app.listen(PORT, function () {
console.log(`Server started at Port ${PORT}`);
});