Here are my code
i want to represent the my data on frontend by hitting a specific API using get request it should respone with json objects
here is my code :
server.ts
import express from 'express';
const app = express();
const PORT = 3000;
interface Account {
id: number;
name: string;
accType: string;
email: string;
Data_Acc_created: Date;
balance: number;
Nooftransaction: number;
}
let data: Account[] = [{id: 1, name: "example", accType: "Saving",email:"[email protected]", Data_Acc_created: new Date("2015-01-16"), balance: 100, Nooftransaction: 0},
{id: 2, name: "test", accType: "Current",email:"[email protected]", Data_Acc_created: new Date("2016-01-16"), balance: 200, Nooftransaction: 2}]
app.get('/account/:id',(req:any,res:any)=>{
const id = parseInt(req.params.id);
const getAccount = data.find(element => element.id === id);
if(!getAccount){
res.status(500).send("account not found");
}else{
res.json(getAccount);
}
});
app.post('/createnewaccount', (req:any, res:any)=>{
const {name, accType, email} = req.body;
const newAccount = {
id : data.length + 1,
name,
accType,
email,
Data_Acc_created : new Date(),
balance : 0,
Nooftransaction : 0
}
data.push(newAccount);
})
app.listen(3000, () =>
console.log('Example app listening on port 3000!'),
);
module.exports = app;
here is my index.html
<!DOCTYPE html>
<html>
<head>
<title>Account Details</title>
</head>
<body>
<script src = "server.js"></script>
</body>
</html>
im not front end guy but any procedure to do this would be helpful