const express = require('express'); | |
const app = express(); | |
const port = 3000; | |
// Middleware untuk parsing JSON | |
app.use(express.json()); | |
// Contoh data yang akan diberikan sebagai output | |
const data = [ | |
{ id: 1, name: 'John Doe', email: '[email protected]' }, | |
{ id: 2, name: 'Jane Smith', email: '[email protected]' }, | |
{ id: 3, name: 'Michael Johnson', email: '[email protected]' } | |
]; | |
// Endpoint GET untuk mendapatkan semua data | |
app.get('/api/data', (req, res) => { | |
res.json(data); | |
}); | |
app.listen(port, () => { | |
console.log(`Server berjalan di http://localhost:${port}`); | |
}); |