In our daily work, we often use NPM to download the dependencies we need. After you have made some “wheels” to improve the team and your own development efficiency, do you want to put them on NPM and let more people use them? Now let’s implement this function step by step.

  • Create an empty folder
  • NPM init initializes the creation of package.json
package.json
{
  "$name-exp": "The name that will be posted on the NPM website, such as NPM install LZQ, using LZQ"."name": "lzq"."version": "1.0.0"."description": ""."main": "index.js"."scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "$keywords-exp": "Keywords in NPM search"."keywords": [
    "lzq"]."author": "lzq"."$license-exp": "Agreement"."license": "MIT"."bin": {
    "lzq": "./bin/www.js"}}Copy the code
  • Create a bin folder in the parent directory and add the boot environment (www.js)

– Enter command line NPM link, which maps to the global package according to the bin directory in package.json