While developing web application there may be situation where we have millions of data and we need to show the data with limited data at once. So for handling such situation we use serverside pagination, So now we are going to discuss the same while using nodejs and monodb at backend.
So let's have a look on our code(server.js),
In the above code we have created app with express and then created connection with data using mongoose. After that we have fetched the current page of data so that data for the page can be fetched accordingly. And after finding the current page and size of the record we passed that data into mongoose model so that data can be fetched accordingly.
After installing all the dependencies of the app, start the application with node server.js and type http://localhost:3000/coins/1/20.
We will get data on the page like below
Pretty cool! Finally, our task completes here.
That’s all for now. Thank you for reading and I hope this post will be very helpful.
Let me know your thoughts over the email demo.jsonworld@gmail.com. I would love to hear them and If you like this article, share with your friends.