-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathstep_04.js
More file actions
30 lines (23 loc) · 808 Bytes
/
step_04.js
File metadata and controls
30 lines (23 loc) · 808 Bytes
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
// Week 08 Express: More Complex Routing
// Step 04
// Import the express library
const express = require('express')
var bodyParser = require('body-parser')
// Create an instance of express
const app = express()
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }))
// Declare a port to run on
const port = 3000
// Declare a route
app.get("/", (req, res) => {
res.sendFile(__dirname + '/public/form.html')
})
app.post("/", (req, res) => {
let firstname = req.body.firstname
let lastname = req.body.lastname
let message = "Hello, " + firstname + " " + lastname
res.send(message)
})
// Start Express Web Server i.e. start listing on the port you defined
app.listen(port, () => console.log(`Example app listening on port ${port}!`))