Nodejs ready file name from path - node.js

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

Related

Error: ENOENT: no such file or directory -Heroku

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.

iisnode not able to access file present in network file path

I am node app through iisnode. I can access file present in network path but when the application tries to access the file, it complains ' File doesn't exist'.
I tried adding IIS_IUSRS user group to have access to iisnode www directory in my local machine. I changed the username(from application pool) of the application to which I have permission(R/W) on the network path. Restarted my machine. But still problem persist.
Can someone help me if there is issue between iisnode and network file path.
const csv=require('csvtojson');
function fetchFile(){
sUsagefile ="\\\\abc\\xyz\\com.csv" .
csv().fromFile(sUsagefile));
console.log(sUsagefile);
}
Error: File does not exist. Check to make sure the file path to your csv is correct.
at C:\iisnode\www\node_modules\csvtojson\v2\Converter.js:81:37
at FSReqWrap.cb [as oncomplete] (fs.js:312:19)
I tried to access UNC path with iisnode and it was working perfectly.
Have you tried to grant IUSR and IIS Apppool\ read/writepermission for network path \abc\xyz\com.csv directly?
Besides, have you checked whether \abc\xyz\com.csv can be accessed from file explorer when IIS stop working.
It is suggested to use process monitor tool to monitor what path is read by node.exe. Please download process monitor from here:https://learn.microsoft.com/zh-cn/sysinternals/downloads/procmon then add a filter like “Path contains com.csv". Finally we would know what path the application is trying to read.

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