0
0
Node.jsframework~10 mins

Pagination patterns in Node.js - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to set the default page number to 1 if not provided.

Node.js
const page = parseInt(req.query.page) || [1];
Drag options to blanks, or click blank then click option'
A1
B0
Cnull
Dundefined
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 as the default page number, which may cause confusion.
Using null or undefined which do not default properly.
2fill in blank
medium

Complete the code to calculate the number of items to skip based on page and limit.

Node.js
const skip = (page - 1) * [1];
Drag options to blanks, or click blank then click option'
Apage
Bcount
Climit
Doffset
Attempts:
3 left
💡 Hint
Common Mistakes
Using page instead of limit causes wrong skip calculation.
Using offset or count which are not defined here.
3fill in blank
hard

Fix the error in the MongoDB query to apply pagination correctly.

Node.js
const results = await collection.find().skip([1]).limit(limit).toArray();
Drag options to blanks, or click blank then click option'
A(page - 1) * limit
Bskip
Cpage
Doffset
Attempts:
3 left
💡 Hint
Common Mistakes
Passing page directly to skip causes wrong results.
Using undefined variables like offset.
4fill in blank
hard

Fill both blanks to create a paginated API response with total pages and current page.

Node.js
const totalPages = Math.ceil(totalItems / [1]);
const response = { currentPage: [2], totalPages };
Drag options to blanks, or click blank then click option'
Alimit
Bpage
Cskip
Dcount
Attempts:
3 left
💡 Hint
Common Mistakes
Using skip instead of limit for total pages calculation.
Mixing up page and skip values.
5fill in blank
hard

Fill all three blanks to implement cursor-based pagination with limit and cursor parameters.

Node.js
const query = {};
if ([1]) {
  query._id = { $gt: [2] };
}
const results = await collection.find(query).limit([3]).toArray();
Drag options to blanks, or click blank then click option'
Acursor
Climit
Dpage
Attempts:
3 left
💡 Hint
Common Mistakes
Using page instead of cursor for _id comparison.
Not limiting the results properly.