Try to save file using path.join(__dirname)
Closed this issue · 4 comments
Hai, is there any certain way to store dump file using path.join(__dirname), because I want to safe the file in different folder.
Thanks
https://github.com/bradzacher/mysqldump#usage
Does the readme not detail this well enough?
https://github.com/bradzacher/mysqldump#usage
Does the readme not detail this well enough?
Of course it does. Everything went well when I running local on Mac. But, when my team try to run on Windows, and using PM2, dumpToFile: './dump.sql'
the location and file doesn't want to be read. Then we try to using path.join
but still get error:enoent no such file or directory
.
I know I miss something here, any help would be appreciated.
What is PM2? What does it do?
There's actually nothing magic about the code - it just uses standard fs
functions passing the exact path you provide in the options.
This lib essentially just does fs.writeFileSync(options.dumpToFile, fileContents)
.
Lines 111 to 113 in fe4f4a2
(it's not exactly that simple, because it streams to the file via fs.appendFileSync
after clearing it, but it's not much different)
Lines 155 to 157 in fe4f4a2
If you pass an absolute path in for options.dumpToFile
, fs will just use that path.
If you pass a relative path in for options.dumpToFile
, fs will (AFAIK) resolve the path to path.join(process.cwd(), options.dumpToFile)
.
I would consider debugging your environment via manually writing to the file via fs.writeFileSync
, and by testing for file existence via fs.existsSync
.
What is PM2? What does it do?
There's actually nothing magic about the code - it just uses standard
fs
functions passing the exact path you provide in the options.This lib essentially just does
fs.writeFileSync(options.dumpToFile, fileContents)
.
Lines 111 to 113 in fe4f4a2
(it's not exactly that simple, because it streams to the file via
fs.appendFileSync
after clearing it, but it's not much different)
Lines 155 to 157 in fe4f4a2
If you pass an absolute path in for
options.dumpToFile
, fs will just use that path.
If you pass a relative path in foroptions.dumpToFile
, fs will (AFAIK) resolve the path topath.join(process.cwd(), options.dumpToFile)
.I would consider debugging your environment via manually writing to the file via
fs.writeFileSync
, and by testing for file existence viafs.existsSync
.
Hai @bradzacher after I start manually debugging the environment, now I've successfully store the file in the folder I want to. Thank you for the advice and your kind reply!