简体   繁体   中英

How to configure npm package so that global install puts it on the path?

I've got a node module that I'm trying to publish as a global NPM package, so that when you install with -g, it puts a couple commands in the path automatically.

In this case my module is called ncrypt-stream and it has two commands -- node encrypt.js and node descrypt.js -- I want to be able to run these commands by simply typing encrypt or decrypt from anywhere in the file system.

I know this package is probably reinventing the wheel: it is a learning exercise more than anything.

Thanks!

Just use the bin option in your package.json to specify binaries.

https://docs.npmjs.com/files/package.json#bin

{ "bin" : { "myapp" : "./cli.js" } }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM