-
Notifications
You must be signed in to change notification settings - Fork 2
/
data-uploader.js
40 lines (30 loc) · 1002 Bytes
/
data-uploader.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
33
34
35
36
37
38
39
40
/**
* Module dependencies.
*/
const request = require('request');
const readline = require('readline');
const fs = require('fs');
const CSV = '../rbc_sectran.csv';
var i = 0;
var pooledRequest = request.defaults({pool: {maxSockets: 100}});
var lineReader = require('readline').createInterface({
crlfDelay: 1000,
input: fs.createReadStream(CSV)
});
lineReader.on('line', function (line) {
var jsonLine = { "csvLine": line };
pooledRequest.post('https://eagles-app.mybluemix.net/api/transactions',
// pooledRequest.post('http://localhost:3000/api/transactions',
{ json: jsonLine },
function (error, response, body) {
if (!error) {
if(response.statusCode == 200) { console.log('uploaded ', ++i); }
if(response.statusCode == 204) { console.log('skipped '); }
} else {
console.log('error: ', error);
console.log('response: ', response);
console.log('body: ', body);
}
}
);
});