Reading specific line from a file in function node

Hello everyone,

i'm kinda new both to node-red and java script and i was trying to log data on a file and then read back a single line from an arbitrary position.

For the first part, i simply used the node-red File node, appending to a file the new data and enabling the "Add newline" option.

For the reading part, after some researching i came to the conclusion that perhaps i could use the node.js module called "nthline". So i installed it globally through npm and then went to node-red settings.js to add the line nthline:require('nthline') to the functionGlobalContext section.

Then in the function node of my flow i added:

var getline = global.get('nthline');

msg.payload = getline(5, '/home/test/testfile.txt');

return msg;

but in the debug window, the message the function node outputs has empty payload.

What did i do wrong? Is there maybe a betetr way to read a single specific line from a file?

Thanks in advance

Welcome to the forum @KiwiTrinitrotoluene

nthline doesn't work like that, it returns a Promise which you have to use to wait for the result. Have a look at the readme to see how to use it. https://www.npmjs.com/package/nthline

Oh, thanks for pointing it out! I missed somehow how a Promise works.