task 12
Fri Nov 01 2024 20:08:09 GMT+0000 (Coordinated Universal Time)
Saved by
@wt
<!-- index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Form Submission</title>
</head>
<body>
<form action="/submit-form" method="POST">
<label for="name">Name:</label>
<input type="text" id="name" name="name" required>
<br><br>
<label for="email">Email:</label>
<input type="email" id="email" name="email" required>
<br><br>
<button type="submit">Submit</button>
</form>
</body>
</html>
// server.js
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
const port = 3000;
app.use(bodyParser.urlencoded({ extended: true }));
app.get('/', (req, res) => {
res.sendFile(__dirname + '/index.html');
});
app.post('/submit-form', (req, res) => {
const { name, email } = req.body;
res.send(Hello, ${name}! We have received your email: ${email}.);
});
app.listen(port, () => {
console.log(Server is running on http://localhost:${port});
});
content_copyCOPY
Comments