'how do you create a folder and write to heroku's ephemeral storage?

i'm using nodejs, and when my script uses fs.mkdir nothing seems to happen... it works well locally. is there an alternate command/function i can use to create and write to folders in heroku's file system?

(yes i'm aware the ephemeral system is temporary, with my use case, all files will be deleted after 5 minutes)



Solution 1:[1]

You can create a tmp folder in the root of your project, which is where you will write to and read files from in Heroku. For instance, first line of code below allows you to save data to a specified file path inside the tmp folder. The second line creates the stream for that file

        fs.writeFileSync(`/tmp/${filename}.json`, dataToSave)
        const fileStream = fs.createReadStream(`/tmp/${filename}.json`)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 bguiz