Reputation: 3415
I'd like to save all files to an external folder outside of my node application. I'm getting an error, ENOTDIR: not a directory
.
backend
├──routes
│ └──savefiles.js
│
externalFolder
How do you write to the external folder?
fs.writeFileSync('../../externalFolder/report.docx', buffer);
.
Upvotes: 0
Views: 525
Reputation: 707436
If backend
and externalFolder
are at the same level and the current working directory is the directory containing savefiles.js
, then you need to up one more level with:
fs.writeFileSync('../../../externalFolder/report.docx', buffer);
The first ..
gets you to the routes
directory. The second one gets you to the backend
directory. You need to get to the backend
parent with the third ..
so you can then reach into the externalFolder
directory.
Note, you can debug this yourself with:
console.log(path.resolve('../../externalFolder'));
Also, you can remove a dependence on the current working directory by constructing a path using the module's directory such as:
fs.writeFileSync(path.join(__dirname, '../../../externalFolder/report.docx'), buffer);
Upvotes: 2