Message from JavaScript discussions
May 2018
— 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);
— 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]+/);
— Also, file:/// paths won't work
— Just use a regular path "/home/lvm/COC2/input.txt"
— Thakns, but i got still the same error
— 'FileReader' is not defined
— Did you save it?
— Sure
— I'm not using "FileReader" here
— So you must be running the wrong file