npm install paginate-middleware
const paginate = require("paginate-middleware")
you will be passing a mongoose model just like below
const paginate = require("paginate-middleware")
const usermodel = require("usermodel")
app.get("/users", paginate(usermodel),(req,res)=>{
res.json(res.paginatedResult);
})
and the request url will look like below
GET http://localhost:3000/users?page=2&limit=3
which will return page two and the limit of 3 users
Another case study if an array is passed in just like below
let users = ["sixtus","john","micheal","donald","princewill"],
page = 2,
limit= 2
let result = paginate(users,page,limit)
{
next: {
page: 3,
limit: 3
},
previous: {
page: 1,
limit: 3
},
results: [
{3 items},
{3 items},
{3 items}
]
}
so as the res.paginatdResult
- javascript
- node.js
- npm or Yarn
- installation of node.js