NPM custom global command

Time:2022-4-21

NPM custom global command
Install node global command

1、 Create package JSON file, and the creation command is hello

{
  "name": "demo",
  "version": "1.0.0",
  "dependencies": {


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

2、 Set the result of file run index js

#!/usr/bin/env node
console.log('hello world')

3、 In the global installation (to be installed under the root directory of package.json), install the local package to

npm i . -g

4、 Run global command

hello