title: Error analysing the csv database with javascript
body: <p>I'm a doing a project for school using IBM's bluemix and I'm having trouble finding out where is my error. I have a database in CSV that has some parameters (neighbourhood, number of rooms, area in square meters, etc). I also have a JADE file that contains a form that the user have to fill in. In this form, the user will choose how many rooms he wants and everything else. Then, my app in JAVASCRIPT should be able to run the database based on the choices of the user. However, for some reason, the results are not appearing in the webpage as they should.</p>
  
  <p>Here is my code:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>/*eslint-env node*/
  
  //------------------------------------------------------------------------------
  // node.js starter application for Bluemix
  //------------------------------------------------------------------------------
  
  // This application uses express as its web server
  // for more info, see: http://expressjs.com
  var express = require('express');
  
  // cfenv provides access to your Cloud Foundry environment
  // for more info, see: https://www.npmjs.com/package/cfenv
  var cfenv = require('cfenv');
  
  var fs = require('fs');
  
  var parse = require('csv-parse');
  
  // create a new express server
  var app = express();
  
  function seleciona_dados(dados, parametros){
      var resultado = {Bairro: [], quartos: [], area: [], valor: [], endereco: [], img: []};
          for (var i = 1; i &lt; dados.Bairro.length; i++){
              if (dados.Bairro[i] == parametros.bairro &amp;&amp; dados.quartos[i] == parametros.quartos &amp;&amp; dados.area[i] &gt;= Number(parametros.area) &amp;&amp; dados.valor[i] &lt;= Number(parametros.valor)){
                  resultado.bairro.push(dados.bairro[i]);
                  resultado.quartos.push(dados.quartos[i]);
                  resultado.area.push(dados.area[i]);
                  resultado.valor.push(dados.valor[i]);
                  resultado.endereco.push(dados.endereco[i]);
                  resultado.img.push(dados.img[i]);
              }
          }
      return resultado;
  }
  
  // serve the files out of ./public as our main files
  app.use(express.static(__dirname + '/public'));
  
  // get the app environment from Cloud Foundry
  var appEnv = cfenv.getAppEnv();
  
  // start server on the specified port and binding host
  app.listen(appEnv.port, '0.0.0.0', function() {
  
   // print a message when the server starts listening
    console.log("server starting on " + appEnv.url);
  });
  var bodyParser = require("body-parser");
   
  app.use(bodyParser.json());
  app.use(bodyParser.urlencoded({ extended: true }));
   
  app.get('/', function(req, res){
      res.render('cadastro.jade', {  pageTitle: 'Cadastro Usuário'});
  });
  app.post('/resumo', function(req, res){
      // var furfles = req.body;
  
      var parser = parse({delimiter: ';'}, function(err, data){
          var dados = {bairro: [], quartos: [], area: [], valor: [], endereco: [], img: []};
          for (var i = 1; i &lt; data.length; i++){
              dados.bairro.push(data[i][0]);
              dados.quartos.push(data[i][1]);
              dados.area.push(Number(data[i][2]));
              dados.valor.push(Number(data[i][3]));
              dados.endereco.push(data[i][4]);
              dados.img.push(data[i][5]);
          }
          dados = seleciona_dados(dados, req.body);
          res.render('resumo.jade', {pageData:{  pageTitle: 'Resumo do Pedido do Usuário'}, formData: req.body, imoveis: dados});
      });
  
      fs.createReadStream(__dirname+'/static/BD.csv').pipe(parser);
   
  });</code></pre>
  </div>
  </div>
  </p>
  
  <p>The list of apartments selected in the database should appear below the last sentence of this image.<a href="http://i.stack.imgur.com/zvTRz.png" rel="nofollow">Page</a></p>