How do I use chmod with Node.js

扶醉桌前 提交于 2019-11-28 08:53:14
qiao

according to its sourcecode /lib/fs.js on line 508

fs.chmodSync = function(path, mode) {
  return binding.chmod(pathModule._makeLong(path), modeNum(mode));
};

and line 203:

function modeNum(m, def) {
  switch (typeof m) {
    case 'number': return m;
    case 'string': return parseInt(m, 8);
    default:
      if (def) {
        return modeNum(def);
      } else {
        return undefined;
      }
  }
}

it takes either an octal number or a string

e.g.

fs.chmodSync('test', 0755);
fs.chmodSync('test', '755');

It doesn't work in your case because the file modes only exists on *nix machines.

The correct way to specify Octal is as follows:

fs.chmodSync('test', 0o755); 

Refer to the file modes here

https://nodejs.org/api/fs.html

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!