-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
32 lines (27 loc) · 1.04 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
var csvsync = require('csvsync');
var fs = require('fs');
const request = require('request');
// Initializing array
var email_array = [];
async function arrayFetch(apikey, file) {
email_array =[];
// Reading user's CSV
var csv = fs.readFileSync(file);
var data = csvsync.parse(csv);
// Iterating through companies
data.forEach(element => {
request('https://api.hunter.io/v2/domain-search?company=' + element +'&api_key='+apikey+'&limit=2&type=personal', (err, res, body) => {
if (err) reject(err)
mainbody = JSON.parse(body);
mainbody.data.emails.forEach(function (key) {
if (key.value) {
email_array.push([[mainbody.data.organization, key.value, key.first_name, key.position]]);
var csvwrite = csvsync.stringify(email_array);
fs.writeFileSync('emails.csv', csvwrite);
return csvwrite;
}
});
});
});
}
module.exports = { arrayFetch };