const tor = require('../lib/tor');

module.exports = (req, res) => {

  let title = 'Top 10 nodes by consensus weight';
  const query = {
    limit: 10
  };
  if(req.query.s) {
    title = `Search results for "${req.query.s}"`;
    query.search = req.query.s;
  } else {
    query.order = '-consensus_weight';
    query.running = true;
  }

  tor.listNodes(query)
    .then(nodes => res.render('listing.html', {
      title: title,
      nodes: nodes
    }))
    .catch(error => res.render('listing.html', {
      error: error
    }));
}

const tor = require('../lib/tor');

module.exports = (req, res) => {

  let title = 'Top 10 nodes by consensus weight';
  const query = {
    limit: 10
  };
  if(req.query.s) {
    title = `Search results for "${req.query.s}"`;
    query.search = req.query.s;
    if(req.query.p) {
      query.offset = (query.limit * req.query.p) - query.limit;
    }
  } else {
    query.order = '-consensus_weight';
    query.running = true;
  }

  tor.listNodes(query)
    .then(nodes => res.render('listing.html', {
      title: title,
      nodes: nodes
    }))
    .catch(error => res.render('listing.html', {
      error: error
    }));
}

Add pagination functionality to query
Add pagination functionality to query
