-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex4.js
More file actions
37 lines (25 loc) · 815 Bytes
/
Copy pathindex4.js
File metadata and controls
37 lines (25 loc) · 815 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
31
32
33
34
35
36
37
import express from "express";
import bodyParser from "body-parser";
import { dirname } from "path";
import { fileURLToPath } from "url";
const __dirname = dirname(fileURLToPath(import.meta.url));
const app = express();
const port = 3000;
function logger(req, res, next){
console.log("Request method: ", req.method);
console.log("Request url: ", req.url);
next();
}
app.use(logger);
app.get("/", (req, res) => {
// console.log(__dirname + "/public/index.html");
res.sendFile("index.html");
});
app.use(bodyParser.urlencoded({ extended: false}));
app.post("/submit", (req, res)=> {
console.log(req.body['street']);
res.send( `<h1>Your band name is</h1> <h2>${req.body['street']} +${req.body['pet']} </h2>`);
});
app.listen(port, () => {
console.log(`Listening on port ${port}`);
});