Socket
Socket
Sign inDemoInstall

command-exists

Package Overview
Dependencies
0
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    command-exists

check whether a command line command exists in the current environment


Version published
Maintainers
1
Install size
10.5 kB
Created

Package description

What is command-exists?

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.

What are command-exists's main functionalities?

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.');
  });

Other packages similar to command-exists

Readme

Source

command-exists

node module to check if a command-line command exists

installation

npm install command-exists

usage

async

var commandExists = require('command-exists');

commandExists('ls', function(err, commandExists) {

    if(commandExists) {
        // proceed confidently knowing this command is available
    }

});

promise

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
});

sync

var commandExistsSync = require('command-exists').sync;
// returns true/false; doesn't throw
if (commandExistsSync('ls')) {
    // proceed
} else {
    // ...
}

changelog

v1.2.0

Add support for promises

v1.1.0

Add synchronous version

v1.0.2

Support for windows

Keywords

FAQs

Last updated on 28 Feb 2017

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc