node. js NPM
Common Commands
1.NPM Install module (<> indicates required parameters, [] indicates optional parameters):
(1) npm install (with no args, in package dir)
1) No parameters, package directory
2) Local Installation: By default, all modules declared in Package.json are installed into the Node_modules directory under the current path
3) Global Installation:-g,--global parameter, NPM installs the current package to the global (System directory)
(2) npm install[< @scope >/]<name>
(3) npm install[< @scope >/]<name> @tag
1) Install the version of the package referenced by the tag (the tag must be present in the package's registry data)
EG:NPM install [email protected]
NPM install @myorg/[email protected]
(4) NPM install[< @scope >/]<name>@<verson>
1) Install the version of the specified package (the version must be published to the registry)
EG:NPM install [email protected]
NPM install @myorg/[email protected]
(5) NPM install[< @scope >/]<name>@<verson range>
1) Install the package version that matches the specified version range
EG:NPM install [email protected] ">=0.1.0 <0.2.0"
NPM install @myorg/[email protected] ">=0.1.0 <0.2.0"
(6) NPM Install<tarball file>
1) Install the package located on the file system
2) If you only want to link a dev directory to your NPM root directory, use NPM link:
EG:NPM install./package.tgz
(7) NPM Install<tarball url>
1) Get the path and then install
2) The parameter must start with HTTP//or https://
EG:NPM Install https://github.com/indexzero/forever/tarball/v0.5.6
(8) NPM install<folder>
1) Install a package that is located in a folder on the file system
(9) npm install [< @scope >/] [-s|--save|-d|--save-dev|-o|--save-optional]
1) npm install has 3 optional parameters for saving or updating the package version in the main Package.json:
-S,--save: The package will be added to the dependencies.
-D,--save-dev: The package will be added to the devdependencies.
-O,--save-optional: The package will be added to the optionaldependencies.
2) When saving dependencies to Package.json using any of these options, there are two additional optional flags:
-E,--save-exact: Specifies the exact version of the installation module in the Package.json file.
-B,--save-bundle: The package will also be added to the bundledependencies.
2.NPM Uninstall
(1) NPM Uninstall: for uninstalling packages
(2) command format:
NPM uninstall [< @scope >/]<pkg>[@<version>] ... [-s|--save|-d|--save-dev|-o|--save-optional]
Aliases:remove, RM, R, UN, unlink
(3) Global mode-G, which unloads the current package context as a global package:
1) NPM Uninstall has 3 optional parameters for saving or updating the package version in the main Package.json:
-S,--save: The package will be added to the dependencies.
-D,--save-dev: The package will be added to the devdependencies.
-O,--save-optional: The package will be added to the optionaldependencies.
Eg:
NPM Uninstall sax
NPM Uninstall sax--save
NPM Uninstall @myorg/privatepackage--save
NPM Uninstall Node-tap--save-dev
NPM Uninstall Dtrace-provider--save-optional
3.NPM Update
(1) NPM Update for updating locally installed modules
(2) command format
1) NPM Update [-G] [<pkg> ...]
Aliases:up, upgrade
(3) If older version: npm–depth 9999 update
4.NPM Config
(1) npm Config command for managing configuration files
(2) command format:
1) npm config set <key> <value> [-g|--global]
Setting a configuration parameter
EG:NPM Config set foo:port 80
2) npm config get <key>
Get a configuration parameter
EG:NPM Config Get Foo:port
3) NPM Config Delete <key>
Delete a configuration parameter
EG:NPM Config Delete foo:port
4) NPM Config list
Print configuration parameter list
5) npm Config edit
Directly edit the configuration file
6) NPM Get <key>
7) NPM set <key> <value> [-g|--global]
5.NPM Public
(1) NPM public is used to publish a package
(2) command format:
1) npm public [<tarball>|<folder>] [--tag <tag>] [--access <public|restricted>]
6.NPM Run
(1) If the command is defined in the Scripts field in the Package.json file, you can use the
NPM run to execute the script command.
Eg:
"Scripts": {
"Test": "Mocha",
"Lint": "Eslint lib Bin hot scripts",
"Prepublish": "NPM Run Test && npm run Lint",
"Start": "Node Index.js"
}
NPM Run + colon (:) front: the equivalent of executing a colon (the command behind the:)
7. Important Fields
Property Description
Name Package Name
Version number of the versions package
Description of the description package
Homepage Package's official website path
Name of the author of the author package
Other contributors ' names for contributors packages
dependencies specifies the module on which the project runs
Devdependencies specify the modules on which the project development depends
Repository the type of place where the package code is stored (can be git or svn)
The main main field is a module ID, which is a pointer to the program's main
Project
Keywords keywords
BIN Specifies the location of the executable files for each internal command
scripts specifies the NPM command line abbreviation for running script commands
8. Description
1) Version:
Install a certain version, followed by the "large version. Minor version." Format rules. such as: 1.0.0.
2) ~version:
such as: ~1.0.0. Represents the latest version of 1.0.x installed (>=1.0.0), but the large and minor version numbers do not change.
3) ^version:
such as: ^1.0.0. Represents the latest version of the installation of 1.x.x (>=1.0.0), but the large version number cannot be changed.
4) 1.2.x: Installs 1.2.x.
5) >, >=, <, <=: You can use a comparer to qualify a range of versions, like array comparisons.
6) Version1-version2: equivalent to >=version1 <=version2.
7) Range1 | | Range2: The version satisfies either the Range1 or Range2 two qualifying conditions.
8) Tag: A version that specifies the tag.
9) * or "" (empty string): any version.
Latest: Latest version.
One) http://... or file://... : You can specify the HTTP or local file path under the package as the version.
Git ... Following
Git://github.com/user/project.git#commit-ish
Git+ssh://[email protected]:p roject.git#commit-ish
Git+ssh://[email Protected]/project.git#commit-ish
Git+http://[email Protected]/project/blah.git#commit-ish
Git+https://[email Protected]/project/blah.git#commit-ish
Nodejs NPM Common Commands