Is it possible to run multiple binaries from a single module via npx?
Asked Answered
X

1

22

(Note: I'm using the cowsay module here to illustrate my point)

Without installing a module on my computer I can run it directly via npx with:

npx cowsay Hello!

If I have multiple binaries specified in package.json.

"bin": {
    "cowsay": "./cli.js",
    "cowthink": "./cli.js"
},

I'd also like to do

npx cowthink Hello!

But this fails. Is this because npx runs the module named cowsay and just runs the first command it finds in the "bin" field in package.json?

Is there a way to run cowthink directly from npx?

Xever answered 1/12, 2018 at 14:16 Comment(0)
B
27

As the documentation states,

Unless a --package option is specified, npx will try to guess the name of the binary to invoke depending on the specifier provided

If binary and package names don't match, this is what --package option is for:

npx -p cowsay cowthink Hello!
Bivouac answered 1/12, 2018 at 16:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.