Last active
August 29, 2015 14:12
-
-
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
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
#!/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