Error: ENOENT: no such file or directory -Heroku - node.js

I'm new in web and just started working on NodeJS.
I have deployed an application on Heroku. But when I was saving my images files on my local machine then it was working great, but when I deployed it on Heroku server then my images are not saving and show me error:
Error ENOENT: no such file or directory, open '../public/uploads/1623462977307.png'
Here is My Code:
my FILES_PATH is ../public/uploads Set on Heroku env variables.
I tried all like absolute path, relative path but issue is not resolving.

That error means the ../public/uploads folder doesn't exist. You can fix the error by making sure the folder exists. Create the folder, put an empty file inside it called .gitkeep, and commit the change. This will keep the empty folder in your repository when you push to Heroku.
Keep in mind that Heroku's filesystem is ephemeral/short lived. This means that any images you save on the disk will disappear after you restart or deploy your app. You can't rely on Heroku's filesystem to store images that need to persist for a longer time. Read more here: https://help.heroku.com/K1PPS2WM/why-are-my-file-uploads-missing-deleted
You're better off saving images elsewhere. Have a look at cloud storage solutions such as Cloudinary or AWS S3.

Related

I am trying to deploy my portfolio using heroku but kept getting an application error with code h10

I am trying to deploy my portfolio using Heroku and the web only has an HTML file, a CSS file, and a simple javaScript file. screenshot of all my files are here
I pushed all of these files to Github and linked them to Heroku. Heroku deployed successfully but as I opened the URL, it gives me an application error with code H10. I googled a lot of fixes and tried adding a Procfile file but none seems to have worked. Can Anyone help me with this issue?
You need to know that heroku is not designed to post static websites. Nevertheless if you still would like to upload static website you need to organize your structure to somehow trick Heroku to see your files as an application.
Add composer.json root directory by adding {} inside, and index.php to the root directory,in index.php, add the following line: <?php include_once("home.html"); ?>, change your index.html to home.html. Push them to heroku, now it should work.

Nodejs ready file name from path

I've used FS library to read the file inside a directory, if running in local, this Is ok. But if deploy my app on Cloud, as Heroku, how can I read the file in local machine from a path?
Thanks a lot

App can find view on local but not once uploaded to server

So I have this app:
https://github.com/jfny/SocialGrowth.xyz
If you were to git clone and npm install/npm start on your local, it should work fine.
However when I upload the files to my server and try running, it tells me it is unable to look up one of the views, yet the files haven't changed at all.
Why is this?

node.js createWriteStream doesn't create new file on Heroku

I have following code that works fine on my localhost running node.js 0.12.0. The code creates a new file, and copy data from readable, but it doesn't create new file on Heroku.
var output = fs.createWriteStream('public/images/test/testfile.png');
readable.pipe(output);
I thought it has something to do with the permission, but whenever I change the permission on the folder using heroku run bash and then chmod -R 777 images/ Heroku resets it back to its original permission which is drwx------.
So may be the problem is something else?
Please note that it fails silently, no exception, nothing in the log.
In Heroku a dyno's local file storage is not persistent (besides the git repo files obviously), so if you write a local file and the dyno restarts the file will be gone, and if you start another dyno it won't be able to "see" the file.
heroku run bash starts a new "one-off" dyno (can read about it here: https://devcenter.heroku.com/articles/one-off-dynos), so the file will not be accessible that way.
If you want your data to persist, better use some database or persistent storage addon.

nodejs create/delete local file on windows azure website "local storage"

I created a generic nodejs/expressjs app and git deployed to windows azure website (not web role, or virtual machine).
The folder structure is typical of an expressjs app:
app.js
package.json
routes/
public/
views/
node_modules/
temp_data/
The app can happily create and write files to the temp_data/ folder using nodejs fs.writeFile('temp_data\\temp_file',...,).
These can't be called "local storage", and not sure about the life time of these files. But as the names pointed out, they are temporary files.
The question is that when I tried to delete these files using nodejs fs.unlink('temp_data\\temp_file',...), after fs.exists('temp_data\\temp_file',...), it failed.
Is that because I have permission to write a file, but no permission to delete a file from a deployed folder?

Resources