Hello from Express!
This Express server is running entirely in your browser.
Try these routes:
/api/users - Get all users
/api/time - Get current time
`);
});
// API routes
app.get('/api/users', (req, res) => {
console.log('GET /api/users');
res.json([
{ id: 1, name: 'Alice', email: 'alice@example.com' },
{ id: 2, name: 'Bob', email: 'bob@example.com' },
{ id: 3, name: 'Charlie', email: 'charlie@example.com' }
]);
});
app.get('/api/time', (req, res) => {
console.log('GET /api/time');
res.json({
timestamp: Date.now(),
iso: new Date().toISOString(),
readable: new Date().toLocaleString()
});
});
app.get('/api/random', (req, res) => {
console.log('GET /api/random');
res.json({
number: Math.random(),
dice: Math.floor(Math.random() * 6) + 1
});
});
// 404 handler
app.use((req, res) => {
res.status(404).json({ error: 'Not Found', path: req.path });
});
// Start server
app.listen(3000, () => {
console.log('Express server running on port 3000');
});