title: NodeJS - Create a Promise function that use Sequelize function
body: <p>I am new to Promise and I have difficulty creating a Promise that will include a Sequelize function which already uses Promise.</p>
  
  <p>I would like to something like this:</p>
  
  <pre><code>var geojson = require(path.join(__dirname, 'lib', 'geojson');
  
  router.get('/[0-9]{3}/points.geojson', function(req, res, next){
      var codecs = req.url.split('/')[1];
      geojson.pointsToGeoJSON(codecs).then(function(geoJSON){
          res.writeHead(200, {'Content-Type': 'application/json'});
          res.end(JSON.stringify(geoJSON));
      });
  });
  </code></pre>
  
  <p><strong>./lib/geojson.js:</strong></p>
  
  <pre><code>var path = require('path');
  var Promise = require('promise');
  var Geojson = require('geojson');
  var Point = require(path.join(__dirname, '..', '..', 'models', 'point'));
  
  module.exports = {
      pointsToGeoJSON: function(codecs) {
  
          //this is a Sequelize function
          Point.findAll({where: {codecs : codecs}, raw: true})
          .then(function(points){
              var data = [];
              for(var i=0; i &lt; points.length; i++){
                  points[i].coordinates = JSON.parse(points[i].coordinates);
                  data.push(points[i]);
              }
  
              //this is another asyn function
              Geojson.parse(data, {'crs': {'type': 'name', 'properties': {'name': 'EPSG:3857'}}, 'Point': 'coordinates'}, function(geoJSON){
  
                  //this is what I want the function to return
                  return geoJSON;
              });
          });
      }
  }
  </code></pre>
  
  <p>How can I make the above <code>pointsToGeoJSON</code> function to use Promise, in order to be able to use <code>.then()</code></p>