When returning the path to a file based on a regex, I can console out the path but when I try to access the value, I get an undefined error

I have an express server running. I send an ID of a picture to find and I am using that ID in conjunction with FindFiles from file-regex.

app.get('/images/icons/:id', async (req, res) => {
    const result = await FindFiles('/Users/greg/server/data/', `.*${req.params.id}_1done.tif`);

    let filename = '/Users/greg/server/data/' + result[0].file;
    console.log(filename);
    res.sendFile(filename);
});

When I hit this endpoint in my tests it passes as expected but when I run it locally, and hit it from my react site. I see the following in the console


Server is running on port 3001
/Users/greg/server/data/Amaranthus_dubius_41_1done.tif
file:///Users/greg/server/server.mjs:62
    let filename = '/Users/greg/server/data/' + result[0].file;
                                                                                   ^

TypeError: Cannot read properties of undefined (reading 'file')
    at file:///Users/greg/server/server.mjs:62:84

Node.js v22.7.0

So the console.log outputs the correct filename but errors when trying to access it. I have a feeling it’s something to do when when filename is defined vs used.

I’m tried different combinations of extra variables and console logs.