Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- "use strict";
- var fs = require('fs');
- function doStuff (path){
- fs.readFile(path, function(err, text){
- if(err){
- console.error(err);
- return;
- }
- var splitted = text.toString().split(process.platform === 'win32' ? '\r\n' : '\n');
- var list = [];
- var buf = [];
- var str;
- while((str = splitted.shift()) !== undefined){
- if(str !== ''){
- buf.push(str);
- } else {
- list.push(buf);
- buf = [];
- }
- }
- var handler = function(arr){
- var str = arr.shift();
- if(str){
- console.log(str);
- setTimeout(handler.bind(null, arr), 1000);
- }
- };
- handler(list[Math.floor(Math.random() * list.length)]);
- });
- }
- doStuff('./file.txt');
Advertisement
Add Comment
Please, Sign In to add comment