This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Part 2 | |
var username = 'seanghagstrom' | |
findLikesForPostsByUsername(username, function(err, totalLikes) { | |
if(err) { | |
console.error(err) | |
} else { | |
console.log(username + ' total number of likes: ' + totalLikes) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Part 1 | |
function findLikesForPostsByUsername(username, mainCallback) { | |
async.waterfall([ | |
function(callback) { | |
findUserByUserName(username, callback) | |
}, | |
function(user, callback) { | |
findPostsByUser(user, callback) | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Part 3 | |
var username = 'seanghagstrom' | |
getTweetsPostsRepos(username, function(err, tweetsPostsRepos) { | |
if(err) { | |
console.error(err) | |
} else { | |
console.log(username + ' has this stuff ' + tweetsPostsRepos) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Part 2 | |
function getTweetsPostsRepos(username, callback) { | |
// counter | |
getTweets(username, function(err, results) { | |
if(err) return callback(err) | |
somethingFinished(null, results) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Part 1 | |
function getTweetsPostsRepos(username, callback) { | |
var count = 0 | |
, results = [] | |
function somethingFinished(err, result) { | |
count += 1 | |
results.push(result) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Part 2 | |
var username = 'seanghagstrom' | |
findLikesForPostsByUsername(username, function(err, totalLikes) { | |
if(err) { | |
console.error(err) | |
} else { | |
console.log(username + ' total number of likes: ' + totalLikes) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Part 1 | |
function findLikesForPostsByUsername(username, callback) { | |
findUserByUsername(username, function(err, user) { | |
if(err) return callback(err) | |
findPostsByUser(user, function(err, posts) { | |
if(err) return callback(err) | |
findLikesByPosts(posts, function(err, likes) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Part 2 | |
getFile(path, function(err, message) { | |
if(err) { | |
console.error(err) | |
} else { | |
console.log(message) | |
} | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Part 1 | |
var fs = require('fs') | |
, path = 'my_file.txt' | |
function getFile(path, callback) { | |
try { | |
fs.readFile(path, function(err, data) { | |
if(err) throw err | |
var wrapperMessage = {coolStuff: true, data: data} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs') | |
, path = 'my_file.txt' | |
, file | |
file = fs.readFile(path, function(err, fileData) { | |
if(err) { | |
console.log(err) | |
} else { | |
console.log('success') | |
} |