Skip to content

Instantly share code, notes, and snippets.

@underr
Last active August 29, 2015 14:12
Show Gist options
  • Save underr/6fb85821bc5b738179f7 to your computer and use it in GitHub Desktop.
Save underr/6fb85821bc5b738179f7 to your computer and use it in GitHub Desktop.
Read lines of a file and sort them by status (200 or 404) to files
#!/usr/bin/node
var readline = require('readline');
var fs = require('fs');
var request = require('request');
var inputFilePath = '/home/under/';
var inputFileName = '1.txt';
var output200File = 'urls-200.txt';
var output404File = 'urls-404.txt';
var rl = readline.createInterface({
input : fs.createReadStream(inputFilePath + inputFileName),
output: process.stdout,
terminal: false
});
rl.on('line',function(line){
request(line, function (error, response, body) {
if (!error && response.statusCode === 200) {
fs.appendFile(output200File, line + "\n");
} else {
fs.appendFile(output404File, line + "\n");
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment