1

I am using Heroku and hosted my nodejs backend and it is connected with my GitHub repo but while uploading files from nodejs it is not stored in the GitHub folder can you please suggest to me how can I upload my file to Github

1 Answers1

0

This is not (really) possible.

Heroku is creating a read-only copy of your GitHub repository. The GitHub repository is meant to store your code, not contain any user data.

Ideally you'll want to use a cloud service like AWS S3 or a similar service from a different provider to store the uploads. The uploads will be completely separate from your source code in GitHub. There are tons of tutorials (including one from Heroku) to show you how to do this. Be aware however, that cloud storage has associated costs, so make sure to set a billing alarm (most providers have a limited free-tier, though).

Storing the files in GitHub would cause significant problems and I strongly advice against it. Each file upload would trigger a redeployment of your app to Heroku. There are also file size and usage limits for GitHub repositories. If you're determined to use GitHub for file storage anyways, you could on each upload: clone your repository, add the file, create a commit and push that commit. You would have to handle errors and retry, because uploading two files simultaneously would cause conflicts. I have to emphasize that this is going to cause problems and is significantly more complicated than using a file storage service.

Moritz Mahringer
  • 1,240
  • 16
  • 28