I am trying to create a folder using mkdirp node module. but it is creating with permission 0775 but i am in need to create with 0777 permission. official documentation says it is default to 0777 but in my case it is 0755. can anyone help me? code:

var new_location = 'public/images/u/7/';
mkdirp(new_location, function(err) {
  if (err) {
  } else {
  }
});
share|improve this question
    
not working , tried mkdirp(new_location, {mode: "777"} , function (err) { }); – iam Jan 11 '16 at 11:57
up vote 8 down vote accepted

The documentation states that the default is 0777 & (~process.umask()), which means that your umask value is "subtracted" from the 0777. Since the umask commonly is 002 or 022, you end up with 0775 or 0755.

However, even if you supply a 0777 permission to mkdirp(), the underlying system call will still apply the umask value. To prevent that, you need to clear the umask, create the directory using the permission you want, and (optionally) restore the umask to its previous value:

var oldmask = process.umask(0);
mkdirp(new_location, '0777', function(err) {
  process.umask(oldmask);
  if (err) ...
  ...
});

Alternatively, you can use fs.chmod() to set the correct permissions after the directory was created.

share|improve this answer
    
thanks for giving me this helpful information. – iam Jan 11 '16 at 12:25
    
mkdirp is not creating recursively directory. if my location is : 'public/images/p/'+place_id+'/ls/'; and only i have till /p/ folder. in my case it is generating till place_id. can you help me out from this? – iam Jan 14 '16 at 7:52
    
@iam please create a new question for that – robertklep Jan 14 '16 at 8:29
    
now created. :) – iam Jan 14 '16 at 8:34

try it:

 var fs = require('fs');
 var new_location = 'public/images/u/7/';
 fs.mkdir(new_location , 0755, function (err) {
    if (err) {} 
  });
}

look also here https://nodejs.org/api/fs.html#fs_fs_mkdir_path_mode_callback

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.