I have the following code which helps me extract the text from a text_file line by line:
const fs = require('fs');
const readline = require('readline');
const rl = readline.createInterface({
input: fs.createReadStream('./rooms.txt')
});
// Each new line emits an event - every time the stream receives \r, \n, or \r\n
rl.on('line', (line) => {
console.log(line);
});
rl.on('close', () => {
console.log('Done reading file');
});
This code works. However I have been unable to use the line variable outside of its scope in order to pass it to the function that would actually prompt Alexa to say those line. I have tried using a callback function but it did not work. Any suggestions as to how make use of the "line" variable outside of the scope of
rl.on('line', (line) => {
console.log(line);
});
Grateful!