NPM Install Local Pack
npm install <package_name>
: This command creates the Node_modules directory in the current directory (if it does not already exist) and downloads the package to that directory. the command is installed locally by default.
Which version of the software package is installed?
If there is no Package.json file in the local directory, the latest version of the package is installed.
If there is a Package.json file, install the latest version of the Semver rule that satisfies the package (if any) that is declared in Package.json.
Install Global Packages
npm install -g <package>
: Global installation package.
PACKAGE.JSONNPM Init
npm init
: This command is used to create a package.json.
npm init --yes
Or npm init -y
: Generates the default Package.json from the information that is extracted from the current directory. No questions are raised during the creation process.
If you already have a Package.json file in your directory and you run it, npm install
NPM will look at the dependencies in that file and download the latest version that meets all of them.
The description in the Package.json file helps people find your package in NPM search, so it's useful to have a custom description in Package.json.
You can also fully customize the contents of the Package.json file and the issues raised during Init. This is done by creating a custom. Npm-init.js. By default, NPM will find your home directory./. Npm-init.js
Dependencies and Devdependencies
Dependencies and Devdependencies Specify the packages that the project depends on.
npm install <package_name> --save
The command adds entries to the Package.json dependencies.
npm install <package_name> --save-dev
The command adds entries to the Package.json devdependencies.
NPM Update updates Local package
npm update
: Used to update dependent packages. You need to run the command in the same directory as the Package.json file.
Update Global Packages
npm update -g <package>
: Updates the global package.
npm update -g
: All global packages are updated.
npm outdated -g --depth=0
: Locate the package that needs to be updated.
NPM Uninstall uninstalling Local Packages
npm uninstall <package>
: Removes a package from the Node_modules directory.
npm uninstall --save <package>
: Removes a package from the dependencies of Package.json.
npm uninstall --save-dev <package>
: Removes a package from the devdependencies of Package.json.
In practice, the discovery uses npm uninstall <package>
not only to delete the package in the Node_modules directory, but also to delete the information in the dependencies or devdependencies of the package in Package.json.
Uninstalling Global Packages
npm uninstall -g <package>
: Uninstalls the global package.
Summary : The local command plus-G is the global command.
Reference from: NPM
Original link: 1190000010001155
NPM Install, NPM init, NPM update, NPM Uninstall, and Package.json