Example #1
0
app.get('/gitjobs', function(req, res) {
  jobs.find({
      term : req.query.term
  }, function(err, results){
    if(err){
      return console.log('Error: ', err);
    }

    console.log('Found ==========' + results.length + ' jobs.');
    var positions = [];
    if (results.length) {
      results.forEach(function(job){
        jobs.findById(job.id, function(err, result){
          if(err){
            return console.log('Error: ', err);
          }

          if (!result.how_to_apply.match(/href="([^\'\"]+)/g)) {
            positions.push({
              company: result.company,
              jobTitle: result.title,
              location: result.location,
              description: result.description
            });
          } else {
            positions.push({
              company: result.company,
              jobTitle: result.title,
              location: result.location,
              description: result.description,
              howToApply: result.how_to_apply.match(/href="([^\'\"]+)/g)[0].slice(6)
            });
          }

          if (results.length === positions.length) {
            res.send(positions);
          }
        });
      });
    } else {
      res.send(positions);
    }
  });
})
Example #2
0
app.get('/gitjobs', function(req, res) {
  jobs.find({
      term : req.query.term
  }, function(err, results){
    if(err){
      return console.log('Error: ', err);
    }

    console.log('Found ==========' + results.length + ' jobs.');
    var positions = [];
    if (results.length) {
      results.forEach(function(job){
        jobs.findById(job.id, function(err, result){
          if(err){
            return console.log('Error: ', err);
          }
          console.log('__HOW__TO__APPLY__', result.how_to_apply);
          positions.push({
            company: result.company,
            jobTitle: result.title,
            location: result.location,
            description: result.description,
            // this line crashes when the section contains no url
            howToApply: result.how_to_apply.match(/href="([^\'\"]+)/g)[0].slice(6)
            // companyLogo: result.company_logo
          });
          if (results.length === positions.length) {
            res.send(positions);
          }
        });
      });
    } else {
      res.send(positions);
    }
  });
})