Files
org-todo-pwa/server.js

34 lines
867 B
JavaScript

const express = require('express');
const bodyParser = require('body-parser');
const fs = require('fs');
const path = require('path');
const app = express();
const port = 3044;
app.use(bodyParser.json());
app.use(express.static('public'));
// Endpoint to receive task data and append to file
app.post('/add-task', (req, res) => {
const { subject, description, scheduled } = req.body;
const orgFormattedData = `
* TODO ${subject}
${description}
SCHEDULED: <${scheduled}>
`;
const filePath = path.join(__dirname, 'tasks.org');
fs.appendFile(filePath, orgFormattedData, (err) => {
if (err) {
return res.status(500).send('Error writing to file.');
}
res.send({ message: 'Task added successfully!' });
});
});
app.listen(port, () => {
console.log(`Server running at http://localhost:${port}`);
});