//Gets links and writes dump of profile data to file
//
// import modules.
var async = require("async");
var fs = require('fs');
require('./ProjectClass.js');
var p = require('./parseProjDatafromJSON');
var split = require('./SplitTxtEachProj.js');
var request = require("request");

function d(callback) {
    function writeToFile(data) {
        fs.writeFile('rawProfileContent2.txt', data, function () {
            console.log('file written!!!!!!!!');
            //split.split();
        callback();
        })
    }

// import function to scrape profile
    var GetProfileLinks = require('./GetProfileLinks_FromDump.js');
// all profile urls consist of this url
    var baseURL = 'https://www.lendwithcare.org/';
// calls function from getlinksfromdump module that parses JSON object and returns array of profile links
    var linksArr = GetProfileLinks.getProfileLinks;
// t termporarily stoes data for each scrape to dump to file
    var t = [];

//count responses received
    var responseCount = 0;
//scrape profiles
    for (var i = 0; i < 40; i++) {
        //concatenate base url with profile link url to give request url
        var urlCur = baseURL + linksArr[i];

        request(urlCur, function (error, response, body) {
            t.push(body);
            // increment response counter to keep track of responses received
            if (response) {
                responseCount++
            }
            // this should be set to (last loop value -1) to ensure file is written after
            // all responses have been received
            if (responseCount === 39) {
                writeToFile(t, callback);

            }
        });
    }

}
async.series([
        function tom(callback){
            // get links from casper links collection and scrape each profile then dump all contents
            console.log('step one!');
            d(function(){
                console.log('ok done - now  run alis');
                callback(null, 'two');});
        },
        function alis(callback){
            // split files from dumped contents to individual projs and write to individualprojectsRaw.json
            console.log('step two! - alis run');
            split.split ( callback(null , 'two'));
        },
        function parsey(callback){
            // get links from casper links collection and scrape each profile then dump all contents
            console.log('step three!');
           p.parsey(function(){
                console.log('ok final parse and write done');
                callback(null, 'two');});
        }
    ],
// optional callback
    function(err, results){
        // results is now equal to ['one', 'two']
    });


@@ -515,17 +515,16 @@
 )%0A    %7D%0A
-%0A
 // impor
@@ -537,30 +537,25 @@
 tion to 
-scrape profile
+get links
 %0A    var
@@ -619,99 +619,8 @@
 ');%0A
-// all profile urls consist of this url%0A    var baseURL = 'https://www.lendwithcare.org/';%0A
 // c
@@ -773,16 +773,107 @@
 eLinks;%0A
+// all profile urls consist of this url%0A    var baseURL = 'https://www.lendwithcare.org/';%0A
 // t ter
@@ -1958,36 +1958,49 @@
 ck(null, 'two');
+%0A            
 %7D);%0A
-
         %7D,%0A     
@@ -2209,16 +2209,96 @@
 .split (
+ function() %7B%0A                console.log('calling final step');%0A               
  callbac
@@ -2307,17 +2307,34 @@
 null
- 
 , 't
-wo')
+hree');%0A             %7D
 );%0A 
@@ -2595,26 +2595,16 @@
 l parse 
-and write 
 done');%0A
@@ -2635,19 +2635,20 @@
 (null, '
-two
+four
 ');%7D);%0A 

Update Main.js