-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
25 lines (22 loc) · 698 Bytes
/
server.js
File metadata and controls
25 lines (22 loc) · 698 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
// server.js
const express = require('express');
const fs = require('fs');
const path = require('path');
const app = express();
const port = 3000;
// Route to serve JSON data
app.get('/api/data', (req, res) => {
const filePath = path.join(__dirname, './fata.json'); // Path to JSON file
fs.readFile(filePath, 'utf8', (err, data) => {
if (err) {
console.error('Error reading JSON file:', err);
res.status(500).send('Error reading data');
} else {
res.json(JSON.parse(data)); // Parse and send JSON data
}
});
});
// Start server
app.listen(port, () => {
console.log(`Server is running at http://localhost:${port}`);
});