osx - How to fix node.js on macOS write to file permission denied error? -
i set node.js write file on local folder such:
note: have use sudo chmod 755 req.txt
, sudo chmod 755 bodyhead.txt
set permission of file writable.
fs.writefile('/req.txt', req + '\r\n!ended!\r\n', function(err) { if(err) { return console.log(err); } }); fs.writefile('/bodyhead.txt', bodyhead + '\r\n!ended!\r\n', function(err) { if(err) { return console.log(err); } });
and received:
{ error: eacces: permission denied, open '/req.txt' errno: -13, code: 'eacces', syscall: 'open', path: '/req.txt' }
as as
{ error: eacces: permission denied, open '/bodyhead.txt' errno: -13, code: 'eacces', syscall: 'open', path: '/bodyhead.txt' }
i set node.js write file on local folder...
but you're not writing local folder, you're writing root of filesystem:
fs.writefile('/req.txt', ... ^ root of filesystem
instead, remove leading slashes filenames you're trying write:
fs.writefile('req.txt', ... fs.writefile('bodyhead.txt', ...
Comments
Post a Comment