Is it possible to use a filesystem like node:fs with netlify functions (answered)

Hey,

I just wanted to ask is it possible to write files with the netlify functions (not edge functions)

I just made a lot of functions with nodejs and javascript threw these api functions but as i saw you cant use “node:fs” and create new files / folders and stuff because they are not in the same path and i cant find the path, so is there any other method i can use or did i oversaw something.

Hi @NeikiDev

It is not possible to write (at least permanently) files using Netlify functions.

What is it you are wanting to achieve?

Oh okay, i want to write files because of a file uploader and redirect files like:
i send file to a website forum and it write its to a folder like

example.jpg => /cdn/uploads/example.jpg

but its okay its not really really needed but i search a way now a long time and just wanted to ask here if somebody have an idea how to get that :smiley:

You could (potentially) post a file to a function, have the function read the file, then write it to another location. However, keep in mind that functions only run for 10 seconds by default (with a maximum of 26 seconds.)

but i mean the location of the functions are in a folder the user cant reach or ? because i checked the path of my functions and they are not “public” viewable so i could store it but not reach it on my website, you know. maybe currently there is now way or something its not a big problem just wanted to ask if somebody know a solution

I’m not sure what you mean.

Functions are publicly available.

Example what i mean (sorry for my bad english)

“./.netlify/functions/upload/” is my endpoint thats avaible, in the headers i send file and so on but i can only save the file in that functions folder , but “./.netlify/functions/upload/uploaded-file.jpg” is not working and not that what i want, i want that the file is creating in my folder like:

NOT: “mywebsite.com/.netlify/functions/upload/file.jpg
RIGHT: “mywebsite.com/uploaded/file.jpg

Do you understand it ? xD im sorry for my bad english hope now its understandable that i want to upload files to a certain folder and not to the endpoint of my function (api) where it is not accessable if im not wrong

Simple: i want to make an upload system for files like images and so on and i was currios if there is some way with the netlify functions (because node:fs didnt worked for me or i used something wrong)

This is not possible with a function or any other method using Netlify. Deploys are immutable (see What are Atomic deploys? Immutable deploys? Learn here!) meaning if you want to add a file to your site or change a single line of text on a page, you need to redeploy the site.

Don’t apologise for not having perfect [sic] English. Your English is much better than my Danish, Chinese, Italian, or Turkish—I can barely express the most basic of things in any of them, and would have no hope of posting anything on a forum like this.

1 Like

Uhhh thats great to know big thank you to your fast and great help, so if i push the file threw github (the linked one) and it redeploy that should work, i know thats not a good way but just for my private use maybe something i can think about, anyways thank you for the support and informations :smiley: have a nice weekend my friend. i will take a look into the new stuff and find a way :heart_eyes: see ya

1 Like

Exactly! :smiley:

Any time you push a new commit to the repository, Netlify will automatically rebuild and deploy new/changed files. *(You can also instruct Netlify not to build with [skip ci] or [skip netlify].

1 Like