Skip to main content
Added on 13 April 2018

While this article remains true, by far the best way to do this now is with the npx command, which was released with npm 5.2.

By running npx <command-name>, <command-name> will run without having to reference the location of the .bin folder.

One of the things that always tripped me up was when an npm module claimed it had CLI support. I'd go and try to run the command, only to get an error saying the command wasn't found.

The solution is to reference the location of the CLI tool. For npm modules, this is the .bin folder found within node_modules.

./node_modules/.bin/<package-name> <command-name>

What's better is that any command defined within scripts in the package.json file doesn't even need to reference the node_modules folder:

{
  "scripts": {
    "name": "<package-name> <command-name>"
  }
}