Take the 2-minute tour ×

I'm looking to create a network mounting script in Node that allows the user to mount nfs shares on the server. My code is as follows:

// Create our mount string command.
var str = 'mount -o nolock -t nfs '+ escapePath(p) +' '+ escapePath(mountPoint);

exec(str, function(err, stdout, stderr){
  if (err) return fn(err);
  return fn(null, mountPoint);

But, of course, mounting a network share requires sudo. If I run my node app using sudo, this works fine... but I suspect that this isn't the best approach. Is there a way that I can run the mount command without invoking sudo? ... or at least, without running my app using sudo? What's the best approach here?

share|improve this question
If you use spawn() rather than exec(), you can specify a uid or gid for the command. Its args argument would also probably help with building the command, reducing possible issues from concatenating. –  Jonathan Lonowski Jul 23 '13 at 2:45
Thanks. I had no idea that the uid or gid options existed with using spawn(). Time to read the docs in a bit more detail... –  bento Jul 25 '13 at 16:43
add comment


Your Answer



Browse other questions tagged or ask your own question.