fs.writeFileSync to public error when deployed

Hello, i have created a function to export results into a csv file and then be able to download it by hitting www.website.com/captains.csv (first image) this works fine locally the file gets created in the public directory but when i deploy to netlify i get the following error when i run this function to write the file to public (second image), it works when i comment fs.writeFileSync line

You don’t really get a public directory in AWS Lambda - on which Netlify Functions run. You’d have to write a file to temp:

Thank you for the response, i didn’t know that because i used the structure provided by deploy prisma on netlify so if i write it to temp will it be accessible for download?

No, that would simply write it to temp. To send file to browser, I’d recommend this approach:

1 Like