I'm reading json file in my file directory and works file in
const data = await readFile(join(process.cwd(),'./src/test/data/test/test.json'), 'utf8')
It is not being read in production in vercel.
Tried by directly giving the file path without join.
Well, this would mean that the file path you're trying to read doesn't exist on your production server. Find the correct path and re-adjust the path string
Related
var fs = require('fs');
var obj = JSON.parse(fs.readFileSync('./config.json', 'utf8'));
This is the code for my app (index.js) . It uses a file named config.json using a relative path ./config.json. When I compile this into my mac using $pkg index.js, I obtain a test-macos file that is my app. Both the app and the config.json file are located in the same folder named project (this is why I can use the relative path ./config.json). However, once runnning the app I run into an error:
/Users/amelie/Documents/project/test-macos ;
exit; internal/fs/utils.js:312
throw err;
^ Error: ENOENT: no such file or directory, open './config.json'.
Therefore it seems that my app cannot find the config.json file. I could determine an absolute path but I need these two files to always be together because I need the path in the variable
var obj = JSON.parse(fs.readFileSync('./config.json', 'utf8'));
to be always the same since I share those files to other people and the absolute path would therefore change. Is there a way to do this ?
I have this code to store the file on the server and after sending the file to the user, delete it.
var fileName=`invoice_${Date.now().toString()}.pdf`
await fs.writeFileSync(path.join(__dirname,'invoices',fileName), result.pdf, 'base64');
var filePath=path.join(__dirname,'invoices',fileName)
console.log(filePath)
res.download(filePath,"invoice.pdf",function(){
fs.unlinkSync(filePath)
});
here is my file structure:
Error in heroku log:
UnhandledPromiseRejectionWarning: Error: ENOENT: no such file or directory, open '/app/routes/invoices/invoice_1609956681064.pdf'
I have sorted out my issue, initially, my invoice folder was empty and git did not push empty folders on the repository so I have added a dummy file in my invoice folder, and it worked.
I am creating an electron app and packaging for distribution with electron-builder for windows and Mac. This app creates a folder and some pdfs inside varying based on user input. The pdfs also use an image, which as a node app I was keeping in the root folder of the app.
I managed to write to the desktop using an absolute path.
if (!fs.existsSync(`/Users/${user}/Desktop/2019 Certificates`)){
fs.mkdirSync(`/Users/${user}/Desktop/2019 Certificates`);
}
but when I use this relative path
stampandseal.png
I get the following error:
I expect it to find the png relative to the js file, however I get the following error:
fs.js:121 Uncaught Error: ENOENT: no such file or directory, open 'stampandseal.png'
If I understand your issue correctly, you are trying to copy an image from within the app bundle to the user's desktop. Use __dirname to reference the directory your code is executing in, and then build the path off of that.
The code below is used by my main.js file, which is in the directory containing my app directory. I use upath to build the path and jetpack instead of fs for copying
var fromPath = upath.join(__dirname, "app", "assets", "image.png");
jetpack.copy(fromPath, toPath, { overwrite: true });
I am create a file from a buffer and saving it to my heroku virtual machine:
var wstream = fs.createWriteStream( name + '.wav');
wstream.write(buffer)
wstream.end()
I need to send that file to google cloud storage using its absolute path: Do you know what the path will be?
path = '?'
The application root on Heroku should be /app. So if you have a file named foo.txt in the root of your repo, it would be /app/foo.txt. You can confirm this by opening up a console (e.g. heroku run bash) and running pwd.
I wonder how to get the correct path to file what should be loaded by fs.readFile:
File to load is in the app's root directory.
Starting the app in cli with npm start
var data = fs.readFileSync('settings.json');
works
After packing and starting electron.exe it will lead to
'Error: ENOENT: no such file or directory'
I can fix this for the packaged app with loading by
var data = fs.readFileSync(path.join(process.resourcesPath, 'app', 'settings.json'));
but then the file isn't found runing the app by npm start.
What is the correct way to determine the path to a file in any environement?