> id -u Your_UserName

> id -g Your_UserName

4000 : Hidden File

2000 : System File

1000 : Archive bit

0400 : Individual read

0200 : Individual write

0100 : Individual execute

0040 : Group read

0020 : Group write

0010 : Group execute

0004 : Other read

0002 : Other write

0001 : Other execute

var fs = require('fs');

var file = 'D:\example\example1.js';

//Hide File

fs.chmod(file, 4000, function(err)){

if(err) throw err;

});

//Individual Write On File

fs.chmod(file, 0200, function(err)){

if(err) throw err;

});

//Individual write + execute

fs.chmod(file, 0300, function(err)){

if(err) throw err;

});

//Individual read + write + execute (full access to an individual)

fs.chmod(file, 0700, function(err)){

if(err) throw err;

});

//Change Owner by root user

fs.chown(file, 0, 0, function(err)){

if(err) throw err;

});

In this post we will show you how to alter file permissions in Nodejs. When you are planning to alter the permissions on a file, you might want to change the ownership. In Nodejs we use fs.chown to change the ownership of a file.According to Nodejs fs.chown function accepts four arguments that are path, uid, gid, callback.path : file you wish to perform the ownership alterationuid : integer of the user id on your systemgid : integer of the group id to which the user belongscallback : callback function attached with fs.chownTo determine the User and Group Id Numbers you have to use below commands in TerminalTo Change access mode of the file you can use fs.chmod whioch accepts three arguments that are path, mode, callback.path : file you wish to perform the access mode alterationmode : The integer value of the octal permission codecallback : callback function attached with fs.chmodFile Access Settings of various files are :Where 1 represents execute, 2 represents write and 4 represents readCode :Please Like and Share Codingdefined.com blog, if you find it interesting and helpful.