-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
46 lines (39 loc) · 1.09 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
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/TechnologyContact');
}
//Defining schema
const contactSchema = new mongoose.Schema({
name: String,
phone: String,
email: String,
message: 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('index.pug');
})
// app.get("/contact" , (req,res)=>{
// res.render('contact.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}`);
})