- Create a folder
mkdir bankapp-mock-api
cd bankapp-mock-api
npm init -y
npm i json-server
const jsonServer = require('json-server')
const server = jsonServer.create()
const router = jsonServer.router('db.json')
const middlewares = jsonServer.defaults()
server.use(middlewares)
server.use('/api', router)
server.listen(process.env.PORT || 5000, () => {
console.log('JSON Server is running')
})
{
"users": [
{ "id": 1, "name":"Naresh Kumar H", "email":"nareshkumarh@live.com",
"password":"pass123", "role": "USER"
},
{ "id": 2, "name":"Tushant", "email":"tushant@gmail.com",
"password":"pass123", "role": "ADMIN"
}
],
"accounts":[
],
"transactions":[
]
}
node server.js
http://localhost:5000/api/users
Output:
[
{
id: 1,
name: "Naresh Kumar H",
email: "nareshkumarh@live.com",
password: "pass123",
role: "USER"
},
{
id: 2,
name: "Tushant",
email: "tushant@gmail.com",
password: "pass123",
role: "ADMIN"
}
]
http://localhost:5000/api/users/1
Output:
{
id: 1,
name: "Naresh Kumar H",
email: "nareshkumarh@live.com",
password: "pass123",
role: "USER"
}