-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
29 lines (25 loc) · 835 Bytes
/
Copy pathserver.js
File metadata and controls
29 lines (25 loc) · 835 Bytes
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
const express = require('express');
const path = require('path');
const { saveNote, getTodayNotes } = require('./notes.js');
const app = express();
const PORT = process.env.PORT || 3000;
app.use(express.static(path.join(__dirname, 'public')));
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'public', 'index.html'));
});
app.get('/save-note', (req, res) =>{
const noteText = req.query.text;
if (noteText) {
const savedPath = saveNote(noteText);
res.json({ success: true, path: savedPath });
} else {
res.json({ success: false, message: 'No note text provided' });
}
})
app.get('/api/notes/today', (req, res) => {
const notes = getTodayNotes();
res.json({ notes });
});
app.listen(PORT, () => {
console.log(`Server is running on http://localhost:${PORT}`);
});