Security News
Maven Central Adds Sigstore Signature Validation
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
command-exists
Advanced tools
The command-exists npm package is used to check if a given command is available in the system's PATH. It is useful for Node.js applications that need to ensure certain commands are installed before attempting to execute them.
Synchronous check
This feature allows you to synchronously check if a command exists in the system's PATH.
const commandExistsSync = require('command-exists').sync;
if (commandExistsSync('git')) {
console.log('Git exists!');
} else {
console.log('Git does not exist.');
}
Asynchronous check
This feature allows you to asynchronously check if a command exists in the system's PATH.
const commandExists = require('command-exists');
commandExists('git', function(err, commandExists) {
if(commandExists) {
console.log('Git exists!');
} else {
console.log('Git does not exist.');
}
});
Promise-based check
This feature provides a promise-based interface to check if a command exists, which can be used with modern async/await syntax.
const commandExists = require('command-exists');
commandExists('git')
.then(function(command) {
console.log('Git exists!');
}).catch(function() {
console.log('Git does not exist.');
});
The 'which' package is similar to 'command-exists' as it checks for the existence of a command. It is a Node.js implementation of the Unix 'which' command. It differs in that it provides the path to the executable if it exists, rather than just a boolean indicating existence.
The 'lookpath' package is another alternative that checks if a command exists in the system's PATH. It is similar to 'command-exists' but returns the full path of the command if it exists. It also supports Windows and is designed to be a lightweight solution.
While 'shelljs' is a more comprehensive shell scripting utility library, it includes a 'which' method that can be used to check for the existence of commands, similar to 'command-exists'. It provides additional shell-related functionalities beyond command checking.
node module to check if a command-line command exists
npm install command-exists
var commandExists = require('command-exists');
commandExists('ls', function(err, commandExists) {
if(commandExists) {
// proceed confidently knowing this command is available
}
});
FAQs
check whether a command line command exists in the current environment
The npm package command-exists receives a total of 1,899,870 weekly downloads. As such, command-exists popularity was classified as popular.
We found that command-exists 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.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.