-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
61 lines (47 loc) · 1.66 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
// IMPORTS
const express = require('express');
const path = require('path');
const fs = require('fs');
const app = express();
const port = 80;
// EXPRESS SPECIFIC CONFIGURATION
app.use('/static', express.static('static')); // for serving File using url: /static
app.use(express.urlencoded());
// PUB SPECIFIC CONFIGURATION
app.set('view engine', 'pug'); // set templete engine for pug
app.set('views',path.join(__dirname, 'views')); // set viwes as directory
// ENDPOINTS
app.get('/',(req,res)=>{
const params = { };
res.status(200).render('Home.pug',params);
});
app.get('/contact',(req,res)=>{
const params = { };
res.status(200).render('contact.pug',params);
});
app.post('/contact',(req,res)=>{
let name = req.body.name;
let age = req.body.age;
let gender = req.body.gender;
let address = req.body.address;
let out = `name:${name} age:${age} gender:${gender} address:${address} | `;
console.log(req.body);
params = { };
fs.writeFileSync('output.txt',out);
res.status(200).render('contact.pug',params);
});
// START THE SERVER
app.listen(port,()=>{
console.log(`app started successfully on http://localhost:${port}`);
});
// app.post('/',(req,res)=>{
// let name = req.body.name;
// let age = req.body.age;
// let gender = req.body.gender;
// let address = req.body.address;
// let more = req.body.more;
// const output = `name:${name}, age:${age}, gender:${gender}, address:${address}, more:${more} `;
// fs.appendFileSync('output.txt',output);
// const params = {'message':'Your Form Is Sucessfully submitted'};
// res.status(200).render('index.pug',params);
// })