Created
July 5, 2012 18:32
-
-
Save ianlivingstone/3055549 to your computer and use it in GitHub Desktop.
Configuration Load Example
This file contains hidden or 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
{ | |
"goCrawl":true | |
} |
This file contains hidden or 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
/* | |
* Web Crawler | |
* | |
* Usage: node crawler.js <config-path> <output-path> | |
*/ | |
var path = require('path'); | |
var config = require('./lib/config.js'); | |
var crawler = require('./lib/crawler.js'); | |
function main () { | |
if (process.argv.length < 4) { | |
console.log('Usage: node crawler.js <config-path> <output-path>'); | |
return process.exit(1); | |
} | |
var configPath = path.resolve(process.argv[2]); | |
var outputPath = path.resolve(process.argv[3]); | |
// Load the configs! | |
config.load(configPath); | |
crawler.go(function (err) { | |
if (err) { | |
console.log('Error Occured: ', err); | |
return process.exit(1); | |
} | |
console.log('Crawl Success'); | |
}); | |
} | |
if (require.main === module) { | |
main(); | |
} |
This file contains hidden or 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 crawler = exports; exports.constructor = function crawler () {}; | |
var config = require('./config'); | |
crawler.go = function goCrawl (cb) { | |
if (config.goCrawl === false) { | |
return cb('He said to not crawl!'); | |
} | |
cb(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment