title: Pagination Nodejs express with mysql
body: <p>I'm using node.js express with mysql. I want to make pagination with 10 articles per page. In my node.js api, I've made model and route. These are my model and route. </p>
  
  <p>This is Model News.js:</p>
  
  <pre><code>var db = require('../db');
  var bodyParser = require('body-parser');    
  var Task = {
      getNews: function(callback){
          sql ="select * from t_article"+
               " where publish='Y'"+
               " order by date DESC"
          return db.query(sql,callback);
      },
      getNewsLimit: function(limit,callback){
          sql2 ="select * from t_article"+
           " where publish='Y'"+
           " order by date DESC LIMIT ? "
      ar2 = [limit]
          return db.query(sql2,parseInt([ar2]),callback)
      }
  };
  module.exports=Task;
  </code></pre>
  
  <p>And this is for 
  Route News.js:</p>
  
  <pre><code>var express = require('express');
  var cors = require('cors');
  var router = express.Router();
  var app = express();
  var Task = require('../models/News');    
  router.get('/api/:limit?',function(req,res,next){
  
      if(req.query.limit){
          // var dateFormat = new Date(Date.UTC(req.params.year,req.params.day-1,req.params.month,0,0));
  
          Task.getNewsLimit(req.query.limit,function(err,rows){
  
              if(err)
              {
                  res.json(err);
              }
              else{
  
                   res.json(rows);
              }
          });
       }
      else{
          Task.getNews(function(err,rows){
              if(err)
              {    
                  res.json(err);
              }
              else{    
                   res.json(rows)
              }
          });
     }
  });
  module.exports=router;
  </code></pre>