Skip to content

Instantly share code, notes, and snippets.

@ianlivingstone
Created July 5, 2012 18:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ianlivingstone/3055549 to your computer and use it in GitHub Desktop.
Save ianlivingstone/3055549 to your computer and use it in GitHub Desktop.
Configuration Load Example
{
"goCrawl":true
}
/*
* 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();
}
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