Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Pagination route
- route.get("/pagination/pageNo/:page", paginationController ) //pagination route
- //pagination controller
- const paginationController = async (req, res) => {
- try{
- const numberOfItemNeedToShow = 5; //number of item show in the page
- const {page} = req.params //get data from params or url
- const skipData = ((page - 1) * numberOfItemNeedToShow); //get how many items it need to skip
- const myUser = await User.find().limit(numberOfItemNeedToShow).skip(skipData)
- if(myUser){
- res.json({
- myUser
- })
- }
- }
- catch(error){
- console.log(error);
- res.json({
- error
- })
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement