Node.js API: Add CRUD Operations With Pagination, Filtering, Grouping, and Sorting Capabilities.

Add CRUD and Aggregation operations including Pagination, Sorting, Filtering and Partial Text Search to your Node.js REST API.

Moses Esan
The Startup

--

In my previous Node.js tutorial, I outlined the steps required to build a Node.js Authentication API with Email Verification, Image Upload and Password Reset Using JWT, Passport.js, and Sendgrid.

This tutorial will be a continuation of that tutorial, CRUD operations will be added for an ‘Event’ resource, users’ will have the ability to create, read, update and delete events.

The API will include:

  1. Pagination: users can dictate how many results they want (limit) and can also page through the result by passing the ‘page’ number in the URL query parameters.
  2. Filtering: users can also specify an event date to filter by
  3. Partial Text Search: users can search by event name, regex is utilized to perform a search against the name column in the database.
  4. Grouping: by default, all events are grouped by date, users can set this to false
  5. Sorting: results can be sorted in ascending order(asc), which is the default or in descending order (desc)

Mongoose Aggregate constructor is used along with mongoose-aggregate-paginate-v2, a cursor based custom pagination

--

--