Skip to main content

Read and save temporary files

You'll need to activate the fs and path Node's libraries to access Spell's file system in Dependencies.

Enable fs and path

Then you can read and write files from the local /tmp directory like this:

//Write a new file named "test" inside the tmp directory and putting inside the content "Hello World"
fs.writeFileSync('/tmp/test', "Hello World");

//Loading the file's content inside a Buffer
const fileContentBuffer = fs.readFileSync('/tmp/test');

//Convertir Buffer to string to use the content
const fileContentAsString = fileContentBuffer.toString();

You must use the /tmp folder to write and read files inside your Spell.

You have 512MB of storage per Spell and this storage is not persistent (all files are destroyed at the end).

If you want to store larger and persistent files, we recommend you to use File Storage APIs (like AWS S3)