Here is what I have achieved so far, and it works quite well.
I have added a callback function to use the "try/catch" as per the tutorial.
However, I am missing much of the output data.
I believe this is due to the fit-file-parser module. what do you think?
[{"id":"93f01531.a7adf8","type":"tab","label":"Flow 7","disabled":false,"info":""},{"id":"49c02ec2.bed66","type":"fs-ops-access","z":"93f01531.a7adf8","name":"","path":"path","pathType":"msg","filename":"file","filenameType":"msg","read":true,"write":true,"throwerror":true,"x":490,"y":100,"wires":[["755cf720.9aafa8"],[]]},{"id":"94916ef8.2bb0d","type":"inject","z":"93f01531.a7adf8","name":"file (right path)","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":180,"y":100,"wires":[["aa5f27ce.152ed8"]]},{"id":"aa5f27ce.152ed8","type":"function","z":"93f01531.a7adf8","name":"right path","func":"\nmsg.path = 'C:\\\\Users\\\\Sylvain\\\\Documents\\\\LiNK for Windows\\\\Exported Files\\\\20200607-4x500m\\\\'\nmsg.file = 'Sylvain Boyer 20200607 1030am.fit'\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":340,"y":100,"wires":[["49c02ec2.bed66"]]},{"id":"755cf720.9aafa8","type":"function","z":"93f01531.a7adf8","name":"Fit File Parser (NK file)","func":"// import modules\nvar FitParser = global.get(\"fit-file-parser\").default;\nvar fs = global.get('fs')\n\n// check for settings\nif ( (typeof fs === 'undefined') ) {\n node.error('fs module could not be found in global context')\n return \n}\nif ( (typeof FitParser === 'undefined') ) {\n node.error('FitParser module could not be found in global context')\n return \n}\n// And make sure they are functions\nif ( (typeof fs !== 'object') ) {\n node.error('fs from global context is not an object & it must be')\n return \n}\n\n\n//import the filepath + filename\nvar file = msg.path.concat(msg.file);\nnode.status(file);\n\n// No calback to handle error: risk of nod-red crashing\n/*fs.readFile(file, function (err, content) {\n // Create a FitParser instance (options argument is optional)\n var fitParser = new FitParser({\n force: true,\n speedUnit: 'km/h',\n lengthUnit: 'km',\n temperatureUnit: 'kelvin',\n elapsedRecordField: true,\n mode: 'cascade',\n //mode:'list',\n });\n // Parse your file\n fitParser.parse(content, function (error, data) {\n // Handle result of parse method\n if (error) {\n console.log(error);\n } else {\n console.log(JSON.stringify(data));\n msg.payload = JSON.stringify(data);\n node.send( msg );\n }\n });\n});*/\n\n// Testing a callback fucntion to handle errors and prevent node-red crash\nfs.readFile(file,callback)\nfunction callback(err, data) {\n if (err) {\n node.error('Oops! there is no data: ' + folder, err)\n return\n }\n try {\n data\n var fitParser = new FitParser({\n //put the options here \n });\n fitParser.parse(data, function (error, data) {\n // Handle result of parse method\n if (error) {\n console.log(error);\n } else {\n console.log(JSON.stringify(data)); //by defaukt in the console\n msg.payload = JSON.stringify(data); //build the msg payload + output from the node\n node.send( msg );\n }\n });\n } \n catch (err) {\n node.error('Ouch! Something went badly wrong processing the data', err)\n return\n }\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","x":680,"y":80,"wires":[["d9824cd.203d5b"]]},{"id":"f182bb72.76931","type":"debug","z":"93f01531.a7adf8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":990,"y":80,"wires":[]},{"id":"d9824cd.203d5b","type":"json","z":"93f01531.a7adf8","name":"","property":"payload","action":"","pretty":false,"x":850,"y":80,"wires":[["f182bb72.76931"]]}]