Search code examples
node.jsnode-modulesfs

Possible values for fs.writefile options parameter especially what will be integer for read-only file


In fs.writeFile(file, data, options, callback) function, when it comes to options we can specify mode(integer)

I want to get to know what can be possible integers for different file modes

enter image description here


Solution

  • You can find the file modes available here.

    You can create octals yourself as per documentation.

    An easier method of constructing the mode is to use a sequence of three octal digits (e.g. 765). The left-most digit (7 in the example), specifies the permissions for the file owner. The middle digit (6 in the example), specifies permissions for the group. The right-most digit (5 in the example), specifies the permissions for others.

    Read only should be 0o444

    enter image description here