Contains methods to safely spawn and manage various file system processes. It differs from the standard node.js child_process (https://nodejs.org/docs/v0.11.13/api/child_process.html#child_process_child_process) module in that it intercepts and handles many common errors that might occur when invoking child processes that could cause an application to crash. Most commonly, errors such as ENOENT and EACCESS. This enables an application to be both cleaner and more robust.
Open a file. Pass your callback to fire when it is safe to open the process
(Function)
callback
this
:
Returns whether or not we are running on a windows machine
Boolean
:
Get locale code - eg: en-AU, fr-FR, zh-CN etc.
(String)
String
:
Given the localeCode, return the language code.
(String)
String
:
Given the localeCode, return the country code.
(String)
String
:
Has spawn sync. Returns true if the child_process spawnSync method exists, otherwise false
Boolean
:
Has exec sync. Returns true if the child_process execSync method exists, otherwise false
Boolean
:
Is the path to a file object an executable? Synchronised version of isExecutable
Boolean
:
Is the path to a file object an executable? Boolean result returned as the isExecutable parameter of the passed callback.
(String)
path to test
Boolean
:
returned if opts.sync = true
Syncronised version of safeps.spawn. Will not return until the child process has fully closed. Results can be returned from the method call or via a passed callback. Even if a callback is passed to spawnSync, the method will still be syncronised with the child process and the callback will only return after the child process has closed.
Simple usage example:
var safeps = require('safeps'); var command = ['npm', 'install', 'jade', '--save'];
//a lot of the time you won't need the opts argument var opts = { cwd: __dirname //this is actually pointless in a real application };
var result = safeps.spawnSync(command, opts);
console.log(result.error); console.log(result.status); console.log(result.signal); console.log("I've finished...");
(String)
unix style signal such as SIGKILL or SIGHUP
([Boolean])
Whether to check the executable path.
([String])
Current working directory of the child process
([Array])
Deprecated File descriptors for the child to use for stdio.
([Object])
Environment key-value pairs.
([Boolean])
The child will be a process group leader.
Object
:
{error, pid, output, stdout, stderr, status, signal}
Wrapper around node's spawn command for a cleaner, more robust and powerful API. Launches a new process with the given command. Command line arguments are part of the command parameter (unlike the node.js spawn). Command can be an array of command line arguments or a command line string. Opts allows additional options to be sent to the spawning action.
Simple usage example:
var safeps = require('safeps');
var command = ['npm', 'install','jade','--save'];
//a lot of the time you won't need the opts argument var opts = { cwd: __dirname //this is actually pointless in a real application } function myCallback(error, stdout, stderr, status, signal){ console.log(error); console.log(status); console.log(signal); console.log("I've finished..."); } safeps.spawn(command, opts, myCallback);
(String)
unix style signal such as SIGKILL or SIGHUP
([Boolean])
Whether to check the executable path.
([String])
Current working directory of the child process
([Array])
Deprecated File descriptors for the child to use for stdio.
([Object])
Environment key-value pairs.
([Boolean])
The child will be a process group leader.
this
:
Spawn multiple processes in the one method call. Launches new processes with the given array of commands. Each item in the commands array represents a command parameter sent to the safeps.spawn method, so each item can be a command line string or an array of command line inputs. It is also possible to pass a single command string and in this case calling spawnMultiple will be effectively the same as calling safeps.spawn.
(String)
[i]
.signal unix style signal such as SIGKILL or SIGHUP
([Boolean]
(default 1
)
)
Whether to spawn processes concurrently.
(String)
Current working directory of the child process.
(Array)
Deprecated File descriptors for the child to use for stdio.
(Object)
Environment key-value pairs.
(Boolean)
The child will be a process group leader.
this
:
Syncronised version of safeps.exec. Runs a command in a shell and buffers the output. Will not return until the child process has fully closed. Results can be returned from the method call or via a passed callback. Even if a callback is passed to execSync, the method will still be syncronised with the child process and the callback will only return after the child process has closed. Note: Stdout and stderr should be Buffers but they are strings unless encoding:null for now, nothing we should do, besides wait for joyent to reply https://github.com/joyent/node/issues/5833#issuecomment-82189525.
(Object)
([Boolean])
true to execute sync rather than async
([String])
Current working directory of the child process
([Object])
Environment key-value pairs
([String]
(default 'utf8'
)
)
([String])
Shell to execute the command with (Default: '/bin/sh' on UNIX, 'cmd.exe' on Windows, The shell should understand the -c switch on UNIX or /s /c on Windows. On Windows, command line parsing should be compatible with cmd.exe.)
([Number]
(default 0
)
)
([Object])
Name | Description |
opts.killSignal [String]
(default 'SIGTERM' )
|
|
opts.uid [Number]
|
Sets the user identity of the process. |
opts.gid [Number]
|
Sets the group identity of the process. |
opts.maxBuffer [Number]
(default 200*1024 )
|
Largest amount of data (in bytes) allowed on stdout or stderr - if exceeded child process is killed. |
Object
:
{error, stdout, stderr}
Wrapper around node's exec command for a cleaner, more robust and powerful API. Runs a command in a shell and buffers the output. Note: Stdout and stderr should be Buffers but they are strings unless encoding:null for now, nothing we should do, besides wait for joyent to reply https://github.com/joyent/node/issues/5833#issuecomment-82189525.
(Object)
([Boolean])
true to execute sync rather than async
([String])
Current working directory of the child process
([Object])
Environment key-value pairs
([String]
(default 'utf8'
)
)
([String])
Shell to execute the command with (Default: '/bin/sh' on UNIX, 'cmd.exe' on Windows, The shell should understand the -c switch on UNIX or /s /c on Windows. On Windows, command line parsing should be compatible with cmd.exe.)
([Number]
(default 0
)
)
([Object])
Name | Description |
opts.killSignal [String]
(default 'SIGTERM' )
|
|
opts.uid [Number]
|
Sets the user identity of the process. |
opts.gid [Number]
|
Sets the group identity of the process. |
opts.maxBuffer [Number]
(default 200*1024 )
|
Largest amount of data (in bytes) allowed on stdout or stderr - if exceeded child process is killed. |
this
:
Exec multiple processes in the one method call. Launches new processes with the given array of commands. Each item in the commands array represents a command parameter sent to the safeps.exec method, so each item can be a command line string or an array of command line inputs. It is also possible to pass a single command string and in this case calling execMultiple will be effectively the same as calling safeps.exec.
(Stream)
[i]
.stderr error buffer
([Boolean]
(default 1
)
)
Whether to exec processes concurrently.
(String)
Current working directory of the child process.
(Array)
Deprecated File descriptors for the child to use for stdio.
(Object)
Environment key-value pairs.
this
:
Get the system's environment paths.
Array
:
string array of file paths
Given an executable name, search and find its actual path. Will search the standard file paths defined by the environment to see if the executable is in any of those paths.
(Object)
this
:
Get home path. Returns the user's home directory. Based upon home function from: https://github.com/isaacs/osenv
this
:
Path to the evironment's temporary directory. Based upon tmpdir function from: https://github.com/isaacs/osenv
this
:
Path to the evironment's GIT directory. As 'git' is not always available in the environment path, we should check common path locations and if we find one that works, then we should use it.
this
:
Path to the evironment's Node directory. As 'node' is not always available in the environment path, we should check common path locations and if we find one that works, then we should use it
this
:
Path to the evironment's NPM directory. As 'npm' is not always available in the environment path, we should check common path locations and if we find one that works, then we should use it
this
:
Initialize a git Repository. Requires internet access.
(Object)
Name | Description |
opts.remote [String]
(default 'origin' )
|
|
opts.url String
|
url to git remote repository |
opts.branch [String]
(default 'master' )
|
|
opts.log String
|
|
opts.output String
|
|
opts.path String
|
path to initiate local repository |
opts.cwd [String]
(default process.cwd() )
|
Current working directory of the child process. |
(String)
[i]
.signal unix style signal such as SIGKILL or SIGHUP
this
:
Pull from a git repository if it already exists on the file system else initialize new Git repository. Requires internet access.
(Object)
Name | Description |
opts.remote [String]
(default 'origin' )
|
|
opts.url String
|
url to git remote repository |
opts.branch [String]
(default 'master' )
|
|
opts.log String
|
|
opts.output String
|
|
opts.path String
|
path to local repository |
opts.cwd [String]
(default process.cwd() )
|
Current working directory of the child process. |
(String)
[i]
.signal unix style signal such as SIGKILL or SIGHUP
this
:
Init Node Modules with cross platform support supports linux, heroku, osx, windows
(Object)
this
:
Spawn Node Modules with cross platform support supports linux, heroku, osx, windows spawnNodeModule(name:string, args:array, opts:object, next:function) Better than https://github.com/mafintosh/npm-execspawn as it uses safeps
(String)
(String)
unix style signal such as SIGKILL or SIGHUP
(Object)
Name | Description |
opts.name String
|
name of node module |
opts.cwd [String]
(default process.cwd() )
|
Current working directory of the child process. |
(Array)
(Object)
(Stream)
out stream
(Stream)
error stream
(Number)
node.js exit code
(Function)
this
: