-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
46 lines (39 loc) · 939 Bytes
/
server.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 bodyParser = require('body-parser');
const app = express();
let userGoal = 'Learn Docker!';
app.use(
bodyParser.urlencoded({
extended: false,
})
);
app.use(express.static('public'));
app.get('/', (req, res) => {
res.send(`
<html>
<head>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<section>
<h2>My Course Goal</h2>
<h3>${userGoal}</h3>
</section>
<form action="/store-goal" method="POST">
<div class="form-control">
<label>Course Goal</label>
<input type="text" name="goal">
</div>
<button>Set Course Goal</button>
</form>
</body>
</html>
`);
});
app.post('/store-goal', (req, res) => {
const enteredGoal = req.body.goal;
console.log(enteredGoal);
userGoal = enteredGoal;
res.redirect('/');
});
app.listen(80);