-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
56 lines (48 loc) · 1.29 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
const express = require("express");
const fs = require("fs");
const path = require("path");
const port = 80;
const app = express();
const mongoose = require('mongoose');
main().catch(err => console.log(err));
async function main() {
await mongoose.connect('mongodb://127.0.0.1:27017/sawanPortfolio');
}
//Defining schema
const contactSchema = new mongoose.Schema({
name: String,
email: String,
phone: Number,
enquiry: String
});
const contact = mongoose.model('contact', contactSchema);
app.use('/static', express.static('static'));
app.use(express.urlencoded());
app.set('views engine', 'pug');
app.set('/views', path.join(__dirname), 'views');
app.get("/", (req, res) => {
res.render('home.pug');
})
app.get("/contact", (req, res) => {
res.render('contact.pug');
})
app.get("/skills", (req, res) => {
res.render('skills.pug');
})
app.get("/cv", (req, res) => {
res.render('cv.pug');
})
app.get("/about", (req, res) => {
res.render('about.pug');
})
app.post("/contact", (req, res) => {
var Mydata = new contact(req.body);
Mydata.save().then(() => {
res.send("Successfully submitted");
}).catch(() => {
res.status(400).send(" ERROR : Not submitted");
})
})
app.listen(port, (req, res) => {
console.log(`server is running on ${port}`);
})