-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
65 lines (48 loc) · 1.58 KB
/
app.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
60
61
62
63
64
65
const express = require("express");
const path = require("path");
// const fs = require("fs");
// const { urlencoded } = require("express");
const app = express();
const port = 90;
const bodyParser = require("body-parser");
const mongoose = require("mongoose");
const { stringify } = require("querystring");
mongoose.connect('mongodb://localhost/contactDance',{useNewUrlParser: true, useUnifiedTopology: true});
//mongoose.connect('mongodb://localhost/customerDetails',{useNewUrlParser: true, useUnifiedTopology: true});
var contactSchema = new mongoose.Schema({
Name: String,
Age: Number,
Phone: Number,
Email: String,
Concern: String,
})
var contact = mongoose.model("Contact",contactSchema);
app.use("/image",express.static("image"));
app.use("/static",express.static("static"));
app.use(express.urlencoded());
app.set("view engine","pug");
app.set("views",path.join(__dirname,"views"))
app.get('/',(req,res)=>{
const parameter = {};
res.status(200).render("index.pug",parameter);
})
app.get('/home',(req,res)=>{
const parameter = {};
res.status(200).render("home.pug",parameter);
})
app.get('/contact',(req,res)=>{
const parameter = {};
res.status(200).render("contact.pug",parameter);
})
app.post('/contact',(req,res)=>{
var myData = new contact(req.body);
myData.save().then(()=>{
console.log("This Item Has Been Saved to DataBase");
res.status(200).render("contact.pug");
}).catch(()=>{
res.status(400).send("Item Was Not Saved");
})
})
app.listen(port,(req,res)=>{
console.log("Listening to Port " + port);
})