javascript - Get line from file - NodeJS function -
how write function returns line file nodejs? program runs in loop, , each time call function should return new string. , if file ends begins again, first line.
function takes randomly, how consistently?
var fs = require('fs'); // random line 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(); }
perhaps help. gets next line , wraps start. based on given getrandsocks
function minimal change.
var current_line = 0; function getnextlines() { var socks = fs.readfilesync('socks.txt').tostring().split("\n"); var randsock = socks[current_line % socks.length]; current_line = (current_line + 1) % socks.length return randsock.split(':'); }
Comments
Post a Comment