linux-command-exists

Check if a command exists

Usage no npm install needed!

<script type="module">
  import linuxCommandExists from 'https://cdn.skypack.dev/linux-command-exists';
</script>

README

linux-command-exists

Check if a command exists

Examples

var commandExists = require("linux-command-exists").commandExists;

//With Promise
commandExists("ls")
  .then(exists => {
    if (exists === true) {
      console.log("The command ls exists");
    } else {
      console.log('The command "ls" doesn\'t exists');
    }
  })
  .catch(e => {
    console.error(`An error happened:\n${e.message}`);
  });

//With Callback
commandExists("ls", (error, exists) => {
  if (error) {
    console.error(`An error happened:\n${e.message}`);
  } else {
    if (exists === true) {
      console.log('The command "ls" exists');
    } else {
      console.log('The command "ls" doesn\'t exists');
    }
  }
});