Read file in custom extension

Hello all,

I am busy to implement extension to convert xml to json. I made decision to use fast-xml-parser because I expect huge files (~150mb) to be imported and only this seems to be useful. Everything works fine if I do it from string in code but I have no clue how to get data from file.
I tried to use readFile() but the output is empty, no errors. Can somebody help with reading files? I tried a lot of options but nothing works…

My code for extension:

const { XMLParser } = require('fast-xml-parser');
var fs = require('fs');

exports.GetJsonXml = function () {

    fs.readFile('/public/xml/full_tst_1item.xml', 'utf8', (err, data) => {
        if (err) {
        var xmlDataStr = data

        // const xmlDataStr = `<product id="48" currency="PLN" code_on_card="A128-18 KHAKI" producer_code_standard="OTHER" type="regular" vat="23.0" site="4">`;

        const options = {
            ignoreAttributes: false,
            alwaysCreateTextNode: true,
            allowBooleanAttributes: true

        const parser = new XMLParser(options);
        const output = parser.parse(xmlDataStr);
        return output

Thanks in advance.

In a custom module you first need to convert the path to any file as described here.

Try this: ‘public/xml/full_tst_1item.xml’

Thanks guys for tips. I figured out that it needs to be ‘/opt/node_app//public/xml/full_tst_1item.xml’ because it is Docker (what I forgot to mention)