This is the 10th day of my participation in Gwen Challenge

1. What is NVM?

NVM is a version management tool for Node. JS, which allows you to install and switch between different versions of NODE. Download a project from GitHub or other sites. Each update is a big change, which is why you need to switch NODE versions frequently

2, NVM for download

1, the Windows version

  https://github.com/coreybutler/nvm-windows/releases
Copy the code

2, the MAC version

  https://github.com/nvm-sh/nvm#install--update-script
Copy the code

3. Differences between NVM, NODE, and NPM

The compatibility between node versions and NPM packages is getting worse. Different Node versions correspond to different NPM package versions. Switching between versions becomes increasingly important when using Node versions. NVM is a great tool for node version management. It is a node development environment, a code base, and a package manager for nodeCopy the code

4. Enter NVM to check whether the NVM is successfully installed

Output: Node Version Manager indicates that the installation is successful. 2 check the NVM Version: NVM --verisonCopy the code

5. Common NVM commands

(1) NVM install stable (2) NVM install <version> ## NVM install v10.12.0 (3) NVM ls-remote check all remote versions if N/A, switch to the Internet, Export NVM_NODEJS_ORG_MIRROR=http://nodejs.org/dist (4) NVM ls View the node version that has been downloaded and installed (5) NVM current View the node version that is currently in use (6) NVM use v10.13.0 Switch to 10.13.0node version (7) NVM alias default 10.12.0 Set the default node versionCopy the code

6. Practical development of NPM package

1, familiar with to Base64 encoding of UM account and password, echo -n 'zhengliming511:2020 @ success | openssl Base64 encoding results: EmhlbmdsaW1pbmc1MTE6MjAyMEBzdWNjZXNz - create NPMRC file, Name = zhengliming511 init.author.email = [email protected] init.author.url = url email = [email protected] always - auth = true _auth = emhlbmdsaW1pbmc1MTE6MjAyMEBzdWNjZXNz - in the package. The new in json "PublishConfig" : {" registry ":" http://maven.paic.com.cn/repository/npm "} - the last step: perform NPM publishCopy the code

7, NPM configuration

1,NPM query the current image - NPM config get registry2NPM sets the mirror1NPM config set registry HTTP://registry.npm.taobao.org/
  2NPM config set registry HTTP://registry.npmjs.org/
  3-npm config set fegistry HTTP://maven.paic.com.cn/repository/npm

 3,Yarn installation and version - Download Node. js use NPM to install NPM install -g Yarn Yarn --version4,Yarn Query the current mirror - Yarn config get registry5,Yarn Sets the mirror1Yarn config set registry HTTP://registry.npm.taobao.org/
  2-yarn config set registry HTTP://registry.yarnpkg.com
  3-yarn config set registry HTTP://maven.paic.com.cn/repository/npm

Copy the code

8. Difference between YARN and NPM

(1) YARN: executes all tasks synchronously, improves performance, and if you installed the package last time, the second one will be retrieved from the cache. (2) NPM: Each package is executed in a queue, each time downloaded from the network, that is, the installation of the current package must be completed before the subsequent installation can proceed

"6.0.3," said / / install the specified 6.0.3 version "~ 6.0.3," said / / install 6.0 X in the latest version of the "^ 6.0.3" said / / install 6. 7.0.x.x in the latest versionCopy the code

9. Compare the YARN and NPM commands

NPM Yarn npm install == yarn npm install vue -g == yarn global add vue npm install vue --save == yarn add vue npm install vue --save-dev == yarn add vue --dev npm uninstall vue --save(-dev) == yarn remove vue npm unpdate vue --save ==  yarn upgrade vueCopy the code

10. Difference between NPM and NPX

* NPM is the node package manager * NPX is the node package execution tool official documentation, from NPM @5.2. 0** NPX is an executable binary file. The principle is very simple. When you run NPX, The default PATH is node_modules/. Bin and the environment variable $PATH to check if the command exists.1, package.json config script {"scripts": {
     "mocha": xxxx
   }
 }
 2Node-modules /.bin/mocha --version now has NPX and can be executed directly: NPX mocka --version *** when executing a package, it will automatically check if it exists locally, if not, it will download it from NPM for you, temporarily install the package and execute it. When you're done, installed packages don't show up in your global installation, so don't worry about global contamination from long-term use. NPX create-react-app my-app installs a temporary create-react-app and calls it without polluting the global setup1.The local project path is checked first to see if the package to execute exists2.If so, execute;3.If it does not exist, which means the package is not installed, NPX will temporarily install its latest version and then execute it;Copy the code

Look to the future

  • With the introduction of YARN, NPM has also made improvements after NPM 5.0, including package-lock.json, which greatly improves speed and performance. Personally, IT is not better than YARN.
  • How to choose, personal advice: most projects can still use NPM, compatibility is good, mature, stable, variety, fun, it is provided with Node, management package security assured,
  • New projects can use YARN, which is a safer choice. With the development of The Times, I find that it has nothing to do with choice, but it is all for the needs of work, to complete the daily work, which one to choose depends on personal preference.