sudo-fn
v2.0.0
Published
Call a node function with sudo privileges (prompts the user for admin privileges with a native OS X dialog)
Downloads
33
Readme
sudo-fn
Call a node function with sudo privileges (prompts the user for admin privileges with a native OS X dialog).
Note: OS X Only
Uses sudo-prompt and cmd-fn.
Installation
npm install sudo-fn
Usage
// To use something other than process.title as the app name.
// Must be alphanumeric (may contain spaces).
sudoFn.setName('Your app name')
// To call a function with admin (sudo) privileges.
sudoFn.call(options, callback);
Options (also see cmd-fn):
module module name e.g.: 'fs'
function function name
params function arguments specified as an array e.g.: ["foo", "bar"]
type the type of target function, can be:
'node-callback' or
'promise'
cwd change working directory context
After calling sudoFn an authentication dialog will display (see below). If challenge is successful then the requested function will be called with admin privileges. The requested function is called in a child process, use absolute paths for non-core modules.
Examples
Simple Local Module Example
If I wanted to do the equivalent of:
require('./foo').bar('baz', {'hello':'world'});
Then I could do:
sudoFn({
module: __dirname + '/foo',
function: 'bar',
params: ['baz', {'hello':'world'}]
}, cb);
Node Callback Example
If I wanted to read a privileged admin directory:
require('fs').readdir("/var/audit", cb);
Then I could do:
sudoFn({
module: 'fs',
function: 'readdir',
params: ['/var/audit'],
type: 'node-callback'
}, cb);
Author
Dave Jeffery (@DaveJ)