How to write a function that returns a line from file with nodeJS? The program runs in the loop, and each time you call the function should return a new string. And if the file ends begins again, with the first line.
This function takes randomly, how to do consistently?
var fs = require('fs');
// Get random line from file
function getRandSocks() {
var socks = fs.readFileSync('socks.txt').toString().split("\n");
var randsock = socks[Math.floor(Math.random()*socks.length)];
return randsock.split(':');
}
function loop() {
// ...
var socks = getRandSocks();
console.log('host: '+socks[0]+'port :'+socks[1]);
//...
loop();
}