May-30, 2021 · 5min
change languageCollect and organize common commands for the npm package manager, including module installation and uninstallation, configuration management, mirror source settings, version control, and other practical techniques.
npm config list
It will generate a package.json file with the information of the current project
npm init
View current mirror source
npm get registry
Set to Taobao mirror source
npm config set registry http://registry.npm.taobao.org/
Set back to the default official mirror
npm config set registry https://registry.npmjs.org/
You can also install cnpm directly
npm install -g cnpm --registry=https://registry.npm.taobao.org
It will create a node_modules directory
npm install <Module Name>
Global installation
npm install <Module Name> --global
# or
npm install <Modele Name> -g
Install in the current directory's node_modules, and add the module information to the package.json's dependencies (production environment dependencies)
npm install <Module Name> --save
# or
npm install <Module Name> -S
Install in the current directory's node_modules, and add the module information to the package.json's devDependencies (development environment dependencies)
npm install <Module Name> --save-dev
# or
npm install <Module Name> -D
npm uninstall <Module Name>
npm search <Module Name>
# View version
npm -v
# Upgrade
npm install npm -g
View current proxy
npm config get proxy
Set proxy
npm config set proxy=http://server:port
If the following error occurs
npm err! Error: connect ECONNREFUSED 127.0.0.1:8087
Solution (clear proxy)
npm config set proxy null
View globally installed modules
npm list -g
npm update <Module Name>
npm cache clear --force