-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
32 lines (26 loc) · 735 Bytes
/
server.js
File metadata and controls
32 lines (26 loc) · 735 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
30
31
32
import express from 'express';
const app = express();
// Set static folder
app.use(express.static('public'));
// Parse URL-encoded bodies (as sent by API clients)
app.use(express.urlencoded({extended: true}));
// Parse JSON bodies (as sent by API clients)
app.use(express.json());
// Handle GET requests to fetch users
app.get('/users', (req, res) => {
const users = [
{id: 1, name: 'Zakbay'},
{id: 2, name: 'Nathan'},
{id: 3, name: 'Alex'}
];
res.send(`
<h1 class="text-2xl font-bold my-4">Users</h1>
<ul>
${users.map((user) => `<li>${user.name}</li>`).join('')}
</ul>
`);
});
// Start Server
app.listen(3000, () => {
console.log('Server listening on port 3000');
});