-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
34 lines (26 loc) · 1.01 KB
/
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
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
const port = 3000;
// Middleware to parse form data
app.use(bodyParser.urlencoded({ extended: true }));
// Serve static files (like HTML and CSS) from the 'public' directory
app.use(express.static('public'));
// Handle form submissions
app.post('/submit-form', (req, res) => {
const { name, email, message } = req.body;
// Here you can add logic to handle the form data (e.g., save it to a database)
// For simplicity, let's just log the data to the console
console.log(`Name: ${name}`);
console.log(`Email: ${email}`);
console.log(`Message: ${message}`);
// You can send a response back to the client if needed
res.send('Form submission successful!');
});
app.listen(port, () => {
console.log(`Server is running on http://localhost:${port}`);
});
// Prints a log once the server starts listening
server.listen(port, hostname, function () {
console.log(`Server running at http://${hostname}:${port}/`);
});