26 lines
698 B
JavaScript
26 lines
698 B
JavaScript
const express = require('express');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
const app = express();
|
|
const PORT = 3000;
|
|
|
|
// Serve static files from the "public" directory
|
|
app.use(express.static(path.join(__dirname, 'public')));
|
|
|
|
// Endpoint to get the list of users
|
|
app.get('/api/users', (req, res) => {
|
|
fs.readFile(path.join(__dirname, 'users.json'), 'utf8', (err, data) => {
|
|
if (err) {
|
|
res.status(500).send('Error reading user data');
|
|
return;
|
|
}
|
|
const users = JSON.parse(data);
|
|
res.json(users);
|
|
});
|
|
});
|
|
|
|
// Start the server
|
|
app.listen(PORT, () => {
|
|
console.log(`Server is running on http://localhost:${PORT}`);
|
|
}); |