Reputation: 9247
I set up node.js to write to file on its local folder as such:
Note: I have already use sudo chmod 755 req.txt
and sudo chmod 755 bodyhead.txt
to set the permission of the file to be 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 well as
{ Error: EACCES: permission denied, open '/bodyhead.txt'
errno: -13,
code: 'EACCES',
syscall: 'open',
path: '/bodyhead.txt' }
Upvotes: 6
Views: 8036
Reputation: 203419
I set up node.js to write to file on its local folder...
But you're not writing to the local folder, you're writing to the root of your filesystem:
fs.writeFile('/req.txt', ...
^ root of filesystem
Instead, remove the leading slashes from the filenames you're trying to write:
fs.writeFile('req.txt', ...
fs.writeFile('bodyhead.txt', ...
Upvotes: 10