const express = require('express');
const fs = require('fs');
const app = express();

// Middleware to parse JSON bodies
app.use(express.json());

// POST endpoint to log activity
app.post('/log-activity', (req, res) => {
    const activityData = req.body;
    const csvLine = `${activityData.timestamp},${activityData.type},${activityData.details}\n`;

    // Append the activity data to the CSV file
    fs.appendFile('activity_log.csv', csvLine, (err) => {
        if (err) {
            console.error('Error writing to CSV file:', err);
            res.status(500).send('Error logging activity');
        } else {
            res.send('Activity logged successfully');
        }
    });
});

// Specify the port to listen on
const port = 3000;
app.listen(port, () => {
    console.log(`Server running on port ${port}`);
});

