Fast write node command-line tool

1, package.json-bin arrangement

[Create a bat file, add the bat path to the PATH] These fixed by the npm work can help us to complete. There is a package.json bin configuration fields :

bin: {
 "commandName1": "path / to / executableFile1",   // path relative package.json directory 
"commandName2": "path / to / executableFile2" , 
}

Executable files can be js file or text file with no extension, and the beginning of the first line of the file is "#! / Usr / bin / env node". It will generate the corresponding configuration script (bat or shell) bin when the installation package according to NPM. If the first line of the executable file is not "#! / Usr / bin / env node", the generated script file simply pointing to the executable file bin configuration.

 

2, for example:

package.json

"bin":{
      "index": "./index.js"
  }

 

In the same directory, create index.js

#!/usr/bin/env node
console.log('heheh');

 

Global Installation

npm install -g index

 

Excuting an order

index

 

After the test is completed, it can be released.

login altitude 
above sea level publish

 

Guess you like

Origin www.cnblogs.com/wenluren/p/11315081.html