Message from JavaScript discussions

May 2018

— Sorry bro... didn't know its the same group..

— 

The only mistake i can see is that you forgot a parentesis at the end to close the map but maybe it happend when you copied the code

— Hi ppl... i simpy need to read a .txt file line by line with any HTML5 need

— How can i do?

— In browser or on server?

— Server

— I just need to populate an array of each line of an input txt file

— Fixed & known path

— I'm using this right now but it raise me an error "Fileread not defined"

— Var reader = new FileReader();
reader.onload = function(e) {
var text = reader.result;
}
reader.readAsText("file:////home/lvm/COC2/input.txt");
console.log(text);

Message permanent page

— Sorry i do not know this language

— 

'use strict';

const { createInterface } = require('readline');
const { createReadStream, readFileSync } = require('fs');

const filepath = "...";

const asyncLines = [];

// async
createInterface({ input: createReadStream(filepath) }).on('line', line => {
// this runs for every line
asyncLines.push(line);
});

// sync
const syncLines = readFileSync(filepath, 'utf8')
.split(/[\r\n]+/);

Message permanent page