-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
78 lines (60 loc) · 1.91 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
66
67
68
69
70
71
72
73
74
75
76
77
78
const request = require('request')
const https = require('https')
const express = require('express')
const mongoose = require('mongoose')
const bodyParser = require('body-parser')
const app = express()
const port = 3000
app.set('view engine', 'ejs')
mongoose.connect('mongodb://127.0.0.1:27017/contactGrowthup', { useNewUrlParser: true })
var db = mongoose.connection
db.on('error', console.error.bind(console, 'connection error:'))
db.once('open', function () {
console.log('We are Connected')
})
// mongoose schema
const contactSchema = new mongoose.Schema({
name: String,
phone: String,
email: String,
message: String
});
// mongoose model
const Contact = mongoose.model('Contact', contactSchema)
// app.post('/contactDbs', function (req, res) {
// var myData = new Contact(req.body);
// myData.save().then(() => {
// res.render('serviceSection')
// }).catch(() => {
// res.status(400).send('This item has not been saved to database')
// });
// })
// app.use(bodyParser.urlencoded({extended:true}));
app.use('/public', express.static(__dirname + '/public'))
app.use('/img', express.static(__dirname + '/img'))
app.use('/views', express.static(__dirname + '/views'))
// app.use('views', path.join(__dirname, 'views'));
app.get('/', function (req, res) {
res.render('home')
})
app.get('/about_Section', function (req, res) {
res.render('about_Section')
})
app.get('/serviceSection', function (req, res) {
res.render('serviceSection')
})
app.get('/contact', function (req, res) {
res.render('contact')
})
app.post('/contactdbs', function (req, res) {
var myData = new Contact(req.body)
console.log(myData)
myData.save().then(() => {
res.send('This item has been saved to database')
}).catch(() => {
res.status(400).send('This item has not been saved to database')
})
})
app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
})