VOOZH about

URL: https://www.geeksforgeeks.org/node-js/how-to-create-pagination-in-node-js-using-skip-and-limit/

⇱ How to Create Pagination in Node.js using Skip and Limit ? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to Create Pagination in Node.js using Skip and Limit ?

Last Updated : 23 Jul, 2025

Creating pagination in Node.js using the skip and limit methods. This approach efficiently retrieves specific data subsets from a database, improving performance and user experience by loading content in manageable segments rather than all at once.

What is Pagination?

Pagination is a very helpful method. This allows the client to fetch data in pages. This is achieved by using options skip and limit, giving clients full control of the page(data) they are getting back.

Prerequisites:

When to use Pagination?

As its statement describes, Pagination should be used:

  • When clients should have the control of data they are getting back.
  • Improving User Experience(UX) and Better Navigation.

Steps to SetUp Project

Step 1: Create a new folder for a project using the following command:

mkdir pagination

Step 2: Navigate to our folder using the following command:

cd pagination

Step 3: Initialize npm using the following command and server file:

npm init -y
touch index.js

Step 4: Install required packages using the following command:

npm i express mongoose 

Project Structure:

It will look like the following

👁 Image

Example 1: Without Using Pagination

Run the server using the following command:

node index.js

Inserting into Database: Data is inserted with the help of Postman through the following method:

👁 Image
Inserting Database by making a post request into '/' path through Postman.

Output: Without Pagination

👁 Image
Fetching Data through Postman without using Pagination.

As it could be seen in the above example, Without pagination all the documents will get fetched. To be more clear about the use and need of Pagination. Think of this case when there are thousands of documents rather than just 4.

Example 2: With Using Pagination

For Pagination skip and limit, parameters will be used using the limit and skip method along with find.

Step to Run:Run the server using the following command:

node index.js

Output: With Pagination

👁 Image
Pagination with limit=2 and skip=0 returns the first 2 documents,
Comment

Explore