Search code examples
node.jsnpmcommand-line-interfacenpm-package

my own NPM package not working command not found


If I don't install my own CLI globally, I can't run it with my keyword command. Only if I install the NPM package globally, the start works with my keyword. I would like to install it with the command suggested by NPM and then run it with keyword.

Visit my CLI: https://www.npmjs.com/package/sweetstack

Installation as globally it works, started with sweetstack.

npm i -g sweetstack

Installation as local not working.

npm i sweetstack

Solution

  • This behavior is expected, if your inspect the $PATH environment variables of your shell, you'll see that only the directory containing the globally installed packages is present.

    If you want to install your tool locally (which is a good practice), you then have to run it through npx.

    The associated documentation page details what it does more clearly and it's relation to npm exec : https://docs.npmjs.com/cli/v9/commands/npx

    cd ./your-project
    npm i sweetstack
    
    npx sweetstack