0

I am a bit new to this, I am simply querying data from another server in my nodejs app. And I am not using any local database to save or store anything. I want to paginate my results. But, all examples and code samples that I am seeing using express-paginate are using mongoose or Sequelize. How to paginate without a database ? Please suggest.

MithunS
  • 485
  • 7
  • 28

1 Answers1

1

me make it.

let page = request.payload.page || 1;

let _limit = request.payload.limit || 2;

var _sort = request.payload.sort ||  'field';

var _order = request.payload.order || 'asc';

var list =  [{object}];


let orderBy = _.orderBy(list, _sort, _order);

            let total = orderBy.length,
              start = page * _limit - _limit,
              end = page * _limit,
              pages = list.length / _limit,
              data = orderBy.slice(start, end);

 return {
              total: total,
              rows: data,
              page: page,
              pages: pages
            }
Shankar Shastri
  • 1,134
  • 11
  • 18
Tran Hoang Hiep
  • 544
  • 5
  • 12
  • Well, I thought the express-paginate helps with all of this, so if there was some way to use that but not consume data from db. Thanks though. – MithunS Jun 30 '18 at 04:42