I have a node.js application where I have a function that will create folders if they don't exist and then create files if it doesn't exist. I also have a function that will delete those files and folders. My problem is that when the folders are created they are created as read-only.
I have already tried to use different file permission modes in the option when creating the folder and made sure to create the files with read/write permission.
This is the code that will create the folders and files:
mkdirp.sync(path.join(__dirname, filePath));
for (let i = 0; i < files.length; i++) {
let filePaths = [] // this list will include the filepath for each file
await fs.open(path.join(__dirname, filePaths[i]), "w+", function(error, fd) {
if (error) {
console.error("error writing image: \n\n" + error);
return;
}
fs.writeSync(fd, files[i].buffer, null, "base64");
});
}
This is the code that will delete folders and files:
await del(filePath);
Expected result should be that the application can create and delete files and folders. The actual result is that the application gets an error message saying this:
{ [Error: EPERM: operation not permitted, unlink "filepath"]
errno: -4048,
code: 'EPERM',
syscall: 'unlink',
path: "filepath"
}
error writing image:
Error: EPERM: operation not permitted, open "filePath"
The application has also been tried on Ubuntu where it runs fine.