Product
Socket Now Supports uv.lock Files
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Work with processes safely and easily with Node.js
require('safeps')
npm install --save safeps
var safeps = require('safeps');
openProcess(task)
fire a process task, and keep it open until the task's completion callback fires
task(complete)
spawn(command, opts?, next?)
spawn a process, with respect to the maximum amount of processes we can open at once
command
an array of arguments to executeopts={safe:true, read:true, output:false, stdin:null}
options are also sent on to require('child_process').spawn
safe
whether or not we should attempt to get the absolute executable path of the command to execute via require('safeps').getExecPath
read
whether or not we should listen to the child process's stdout and stderr streams for use in the completion callbackoutput
if set to true
will output the child process's stdout to our process's stdout, and provide those values in the completion callbackoutputPrefix
if set to a string, this string will be outputted before each line of the outputstdin
if set will be written to the child process's stdinnext(err, stdout, stderr, code, signal)
spawnMultiple(commands, opts?, next?)
spawn multiple processes, forwards on to require('safeps').spawn
commands
an array of commands to executeopts={concurrency:1}
options are also sent on to require('safeps').spawn
concurrency
how many processes should we execute at once?next(err, results)
results = [result...]
result = [err, stdout, stderr, code, signal]
spawnCommand(command, args, opts?, next?)
alias of require('safeps').spawn
but with the command
prefixed to the args
, e.g. spawnCommand('git', 'status')
spawnCommands(command, multiArgs, opts?, next?
alias of require('safeps').spawnMultiple
but with the command
prefixed to the multiArgs
, e.g. spawnCommands('git', [['status'],['pull']])
exec(command, opts?, next?)
execute a process, with respect to the maximum amount of processes we can open at once
command
a string to executeopts={output:false}
options are also sent on to require('child_process').exec
output
if set to true
will set the stdio
option to inherit
which will output the child process's stdout and stderr to our ownnext(err, stdout, stderr)
execMultiple(commands, opts, next)
execute multiple processes, forwards on to require('safeps').exec
commands
is an array of commands to executeopts={concurrency:1}
options are also sent to require('safeps').exec
concurrency
how many processes should we execute at once?next(err, results)
results = [result...]
result = [err, stdout, stderr]
determineExecPath(possibleExecPaths, next)
determine an executable path from a list
possibleExecPaths
an array of possible executable paths that we shall evaluatenext(err, execPath)
getEnvironmentPaths()
returns an array of the environment paths for executablesgetStandardExecPaths(execName?)
return an array of the the environment paths for executables with the cwd prepended
execName
if provided, is added onto each of the pathsgetExecPath(execName, next)
get the absolute executable path, forwards to get#{execName}Path
when appropriate
next(err, execPath)
getHomePath(next)
get the user's home path
next(err, homePath)
getTmpPath(next)
get the temporary path
next(err, tmpPath)
getGitPath(next)
get the git path
next(err, gitPath)
getNodePath(next)
get the node path
next(err, nodePath)
getNpmPath(next)
get the npm path
next(err, npmPath)
initGitRepo(opts, next?)
get the git path, forwards on to require('safeps').spawnCommand
opts={cwd:process.cwd(), url:null, remote:'origin', branch:'master'}
options are also sent on to require('safeps').spawnCommand
cwd
the path to initialize the repo tourl
the url to initializeremote
the remote name to associate the url
tobranch
the branch name to initialize the repo tonext(err, results)
, results = [result...]
, result = [err, stdout, stderr, code, signal]
initOrPullGitRepo(opts, next?)
if the path exists, update it, otherwise initialize it, forwards on to require('safeps').spawnCommand
opts={cwd:process.cwd(), url:null, remote:'origin', branch:'master'}
options are also sent on to require('safeps').spawnCommand
next(err, method, results)
method
is either pull
or init
depending on the method usedresults = [result...]
result = [err, stdout, stderr, code, signal]
initNodeModules(opts, next?)
initialize node modules, forwards on to require('safeps').spawn
opts={cwd:process.cwd(), args:[], force:false}
options are also sent on to require('safeps').spawnCommand
cwd
the path to initialize the repo toargs
an array of arguments to add onto the initialize commandforce
whether or not to still initialize modules if node_modules
already existsnext(err, results)
, results = [result...]
, result = [err, stdout, stderr, code, signal]
requireFresh(path)
require the file without adding it to the cacheisWindows()
are we running on windows?getLocaleCode(lang?=process.env.LANG)
get the locale code from a language, e.g. en_au
getLanguageCode(localeCode?=getLocaleCode())
get the language code from a locale code, e.g. en
getCountryCode(localeCode?=getLocaleCode())
get the country code from a locale code, e.g. au
Discover the change history by heading on over to the HISTORY.md
file.
Discover how you can contribute by heading on over to the CONTRIBUTING.md
file.
These amazing people are maintaining this project:
No sponsors yet! Will you be the first?
These amazing people have contributed code to this project:
Licensed under the incredibly permissive MIT license
Copyright © 2013+ Bevry Pty Ltd us@bevry.me (http://bevry.me)
Copyright © 2011-2012 Benjamin Lupton b@lupton.cc (http://balupton.com)
v3.0.0 2015 March 17
spawn
's stdout
and stderr
are now Buffers - If you're upgrading, all you have to do to get the previous functionality is to do stdout.toString()
- outputPrefix
value no longer affects stdout
and stderr
results (only their output to the terminal)hasSpawnSync
- hasExecSync
- isExecutable(path, opts?, next)
- isExecutableSync(path, opts?, next?)
- spawnSync(command, opts?, next?)
- execSync(command, opts?, next?)
exec
now supports outputPrefix
option - The checks to see if an executable path exists and works have been greatly improved and abstracted out from determineExecPath
into isExecutable
and isExecutableSync
- determineExecPath
, getExecPath
, and isExecutable
can now operate synchronously with a callback using the sync: true
option - Retrieval and writing to a path cache can now be disabled using the cache: false
optionFAQs
Work with processes safely and easily with Node.js
The npm package safeps receives a total of 18,817 weekly downloads. As such, safeps popularity was classified as popular.
We found that safeps demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.
Security News
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.