loading files on local machine with node.script and fs

James Bradbury's icon

Can anyone here provide a way of loading files on the local machine with node.script and fs? I am able to do it by providing a file in the same location as the node script with...

const file = fs.readFileSync('./myfile.yaml', 'utf8')

However, I want to pass a directory as an argument to this so I can load a file from wherever I want, rather than in the directory of the node script itself.

Whenever I pass my patcher dir using this patcher it says that it doesn't exist.

James Bradbury's icon

Full code:

const max = require("max-api");
const yaml = require("yaml");
const fs = require("fs");
max.addHandler("read", (...args) => {
    let yaml_file = args[0];
    const file = fs.readFileSync(yaml_file, 'utf8')
    const output = yaml.parse(file);
});    

With my input being something like...

read "/Users/myname/docs/config.yaml"

James Bradbury's icon

And again, for anyone who wants to learn from my own process of figuring this out.

You cannot pass paths from thispatcher to fs without first using `conformpath max boot` to remove the Macintosh HD: from your path (if you're on mac).