title: How to fix node.js on macOS write to file permission denied error?
body: <p>I set up node.js to write to file on its local folder as such:</p>
  
  <p>Note: I have already use <code>sudo chmod 755 req.txt</code> and <code>sudo chmod 755 bodyhead.txt</code> to set the permission of the file to be writable.</p>
  
  <pre><code>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);
    }
  });
  </code></pre>
  
  <p>And received:</p>
  
  <p><code>{ Error: EACCES: permission denied, open '/req.txt' errno: -13, code: 'EACCES', syscall: 'open', path: '/req.txt' }</code></p>
  
  <p>as well as</p>
  
  <p><code>{ Error: EACCES: permission denied, open '/bodyhead.txt'
    errno: -13,
    code: 'EACCES',
    syscall: 'open',
    path: '/bodyhead.txt' }</code></p>