command-exists
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
Command-exists is a handy Node.js module whose primary function is to check if a particular command-line command exists in the current environment. This feature allows your Node.js applications to perform certain actions or change the flow of execution based on the availability of certain command-line tools.
You can install command-exists using npm:
npm install command-exists
You can then use it in three ways:
Async mode: Invoking the commandExists
function with a command and a callback function. The callback will be called with err
and commandExists
arguments, the latter being a boolean indicating the existence of the command.
var commandExists = require('command-exists');
commandExists('ls', function(err, commandExists) {
if(commandExists) {
// proceed confidently knowing this command is available
}
});
Promise mode: If commandExists
is invoked without a callback, it returns a promise that will be resolved with the command if exists, or rejected if it doesn't.
var commandExists = require('command-exists');
commandExists('ls')
.then(function(command){
// proceed
}).catch(function(){
// command doesn't exist
});
Sync mode: The commandExistsSync
function synchronously checks the existence of a command and returns a boolean value.
var commandExistsSync = require('command-exists').sync;
if (commandExistsSync('ls')) {
// proceed
} else {
// ...
}
The most up-to-date and detailed documentation for command-exists can be found in the README file on its GitHub repository at the URL: https://github.com/mathisonian/command-exists
. This readme file includes installation instructions, usage examples for all supported modes, and a chronological changelog with changes made in each version of the package.