I'm trying to make an external module outside my index.js
to make the code more manageable. However, it does not return what I wanted.
Here's my code in index.js
app.post('/resumes', authenticate, (req, res) => {
var body = _.pick(req.body, ['url']);
var url = body.url;
request(url)
.then(function(html){
//success!
html = html.replace(/<(?:.|\n)*?>/gm, '');
html = html.replace(/\t/g, '');
html = html.replace(/\n/g, '');
scrape.searchJob(req.user._id, html).then(jobs => {
res.status(200).send(jobs);
});
})
.catch(function(err){
res.status(400).send({err});
});
});
Here's the scrape.js
:
var request = require('request-promise');
var {Job} = require('../models/job');
var searchJob = ( id, html) => {
var promise = Job.find({_creator: id}).exec(function (err, jobs){
jobs.map((job) => {
job.butter = 'butter';
});
});
return promise;
};
module.exports = {searchJob};
I'm trying to do some modification the jobs
that I got from Job
(mongoose model), yet it still only returns the original data.
I did require scrape.js
in index.js
.
Any help appreciated!