Now I am pretty crappy at software architecture. I think I was able to make this relatively concise. Please, any input is helpful! var cheerio   = require(cheerio),        request   = require(request),        sqlite3   = require(sqlite3).verbose(),        colors    = require(colors),        fs        = require(fs),        fetchPage = require('../common/Utilities').fetchPage();    function parseDateFromHltvDate(dateString) {        var regexPattern     = new RegExp(/(\d{1,2})[/](\d{1,2}) (\d{1,2})/);        var parsedDateString = regexPattern.exec(dateString);        if (parsedDateString) {            return parsedDateString[2] + '/' + parsedDateString[1] + '/' + parsedDateString[3];        }    }    var processMatchRow = function ($, db) {        var regexPattern = new RegExp(/(\d{1,2}[/]\d{1,2} \d{2}) (.*?)[(](\d{1,2})[)] (.*?)[(](\d{1,2})[)](cbble|mirage|cache|dust2|inferno|overpass|train|nuke)(.*)(W|L)/g);        //Getting the url for the invididual match        $(this).children().each(function () {            if ($(this).attr('href') && $(this).attr('href').indexOf('matchid') > 1) {                matchUrl = 'http://www.hltv.org' + $(this).attr('href');            }        });        var fullMatchRowText = $(this).text().trim();        var parsedMatchRow   = regexPattern.exec(fullMatchRowText);        var matchUrl = undefined;        if (parsedMatchRow) {            var date         = parseDateFromHltvDate(parsedMatchRow[1].trim());            var teamOne      = parsedMatchRow[2].trim();            var teamOneScore = parsedMatchRow[3].trim();            var teamTwo      = parsedMatchRow[4].trim();            var teamTwoScore = parsedMatchRow[5].trim();            var map          = parsedMatchRow[6].trim();            var event        = parsedMatchRow[7].trim().replace('_ce', '').replace('_se', '');            var outcome      = parsedMatchRow[8].trim();            //If Outcome is W then TeamOne wins, else TeamTwo.            if (outcome.toLowerCase() === w) {                outcome = teamOne            } else {                outcome = teamTwo            }            var value = [matchUrl, date, teamOne, teamOneScore, teamTwo, teamTwoScore, map, event, outcome];            if (verifyValuesToInsert(value)) {                updateTeamHistoryRow(db, value);            } else {                console.log('Failed to verify values. NOT INSERTING!'.red);            }        }    };    var verifyValuesToInsert = function (value) {        var goodToUpdate = true;        for (var i = 0; i < value.length; i++) {            if (value[i] === undefined) {                goodToUpdate = false;                //console.log('Failed to verify value ' + i + ' @ verifyValuesToInsert!: ' + value.yellow)            }        }        return goodToUpdate;    };    function createUniqueHash(values) {        return JSON.stringify(values);    }    function updateTeamHistoryRow(db, value) {        //Generate a unique hash to identify the row        var hashValue = createUniqueHash(value);        //Now add hashValue to the array of 'value'        value.push(hashValue);        // Insert some data.        var statement = db.prepare(INSERT INTO TeamHistory (MatchUrl, Date, TeamOne, TeamOneScore, TeamTwo, TeamTwoScore, Map, Event, Outcome, UniqueHash) VALUES (?,?,?,?,?,?,?,?,?,?),            [value[0], value[1], value[2], value[3], value[4], value[5], value[6], value[7], value[8], value[9]],            function (err, row) {                if (err) {                    return console.log(err);                }            }        );        //console.log(statement);        statement.run(value,            function (err, row) {                if (err) {                    return console.log(err);                }            });        statement.finalize();    }    var getTeamUrls = function () {        var fTeamUrls = fs.readFileSync('./teamUrls.json').toString();        return JSON.parse(fTeamUrls);    };    function ProcessPage(teamUrl, db) {        var styles = {            'matchRowOdd': 'width:606px;height:22px;background-color:white',            'matchRowEven': 'width:606px;height:22px;background-color:#E6E5E5',            'date': 'width:10%;float:left;',            'teamOne': 'width:23%;float:left;font-weight:normal;',            'teamTwo': 'width:23%;float:left;font-weight:normal;'        };        // Use request to read in pages.        console.log(('Processing ' + teamUrl).blue);        fetchPage(teamUrl, function (body) {            // Use cheerio to find things in the page with css selectors.            var $ = cheerio.load(body);            var isStyleMatch = function (elem, style) {                if ($(elem).attr('style')) {                    return $(elem).attr('style').indexOf(style) > -1                } else {                    return false;                }            };            var matchHistoryWrapper = $('#back div.mainAreaNoHeadline div.centerNoHeadline div div.covMainBoxContent div').each(function () {                //Determine if this is the match URL                var elementChildren = $(this).children().each(function () {                    if (isStyleMatch(this, styles.teamRowOdd) || isStyleMatch(this, styles.teamRowEven)) {                        var childrenofChildren = $(this).children().each(function () {                                processMatchRow.call(this, $, db);                            }                        )                    }                });            });        })    }    exports.GetTeamUrls = function () {        return getTeamUrls();    };    exports.ProcessPage = function (teamUrl, db) {        return ProcessPage(teamUrl, db);    };
Web Scrape, and Save To SQLite DB
javascript;beginner