
Product
Introducing Scala and Kotlin Support in Socket
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.
command-exists
Advanced tools
check whether a command line command exists in the current environment
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
}
});
var commandExists = require('command-exists');
// invoked without a callback, it returns a promise
commandExists('ls')
.then(function(command){
// proceed
}).catch(function(){
// command doesn't exist
});
var commandExistsSync = require('command-exists').sync;
// returns true/false; doesn't throw
if (commandExistsSync('ls')) {
// proceed
} else {
// ...
}
Removes unnecessary printed output on windows.
Small bugfixes.
Fix windows bug introduced in 1.2.4.
Fix potential security issue.
Add support for promises
Add synchronous version
Support for windows
FAQs
check whether a command line command exists in the current environment
The npm package command-exists receives a total of 2,654,546 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.
Product
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.
Application Security
/Security News
Socket CEO Feross Aboukhadijeh and a16z partner Joel de la Garza discuss vibe coding, AI-driven software development, and how the rise of LLMs, despite their risks, still points toward a more secure and innovative future.
Research
/Security News
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.