-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
43 lines (37 loc) · 915 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
const express = require('express')
const app = express()
const PORT = 3000
app.use(express.urlencoded({ extended: true }))
let userGoal = "Learn Docker"
app.use(express.static('public'));
app.get('/', (req, res) => {
res.send(`
<html>
<head>
<link rel="stylesheet" href="style.css">
</head>
<body>
<section>
<h2>My Course Goal</h2>
<h3>${userGoal}</h3>
</section>
<form action="/post" 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('/post', (req, res) => {
const enteredGoal = req.body.goal
userGoal = enteredGoal
console.log(userGoal);
res.redirect('/')
})
app.listen(port, () => {
console.log(`Example app listening on port ${PORT}`)
})