Detailed explanation of common commands of npm in Nodejs
- 2021-07-01 06:42:34
- OfStack
What is npm
NPM, whose full name is Node Package Manager, is a package management and distribution tool installed with NodeJS1, which makes it easy for JavaScript developers to download, install, upload and manage installed packages.
npm is an node package management and distribution tool, which has become the unofficial standard for publishing node modules (packages). With npm, you can quickly find packages to be used by a particular service, download, install, and manage installed packages.
1. npm install moduleNames: Install Node module
After installation, an node_modules directory will be generated, and each node module installed will be in its directory.
The installation of node is divided into global mode and local mode.
1 will normally run in local mode, and the package will be installed in the local node_modules directory with your application code.
In global mode, the Node package is installed under node_modules in the installation directory of Node.
The global installation command is $npm install-g moduleName.
Learn to use $npm set global=true to set the installation mode, and $npm get global can view the currently used installation mode.
Example:
npm install express
The latest version of express will be installed by default, or the specified version can be installed by adding a version number, such as npm install express @ 3.0. 6
npm install <name> -g
Install packages into the global environment
However, in the code, there is no way to call the globally installed package directly through require (). The global installation is for command-line use, as if you can run the vm command directly from the command line after you have installed vmarket globally
npm install <name> --save
At the same time of installation, write the information to the project path in package. json. If there is package. json file, you can install all dependency packages according to dependencies configuration directly by using npm install method, so that when the code is submitted to github, you don't need to submit node_modules.
2. npm view moduleNames: View the package. json folder of the node module
Note: If you want to view the contents of a tab under the package. json folder, you can use $npm view moduleName labelName
3. npm list: Check the installed node packages in the current directory
Note: The Node module search starts in the current directory where the code is executing, and the search results depend on what is under node_modules in the directory currently in use. $npm list parseable=true can show all of the currently installed
node package
4. npm help: View help commands
5. npm view moudleName dependencies: View package dependencies
6. npm view moduleName repository. url: View the source file address of the package
7. npm view moduleName engines: View the version of Node that the package depends on
8. npm help folders: View all folders used by npm
9. npm rebuild moduleName: Used to rebuild after changing package contents
10. npm outdated: Check whether the package is outdated. This command will list all outdated packages and update them in time
11. npm update moduleName: Update node module
12. npm uninstall moudleName: Uninstall node module
13. An npm package is a folder containing package. json, and package. json describes the structure of this folder. The json folder of npm can be accessed as follows:
$ npm help json
This command will open 1 Web page by default. If you change the default opening program, it may not open as a Web page.
14. When publishing an npm package, you need to check whether a package name already exists
$ npm search packageName
15. npm init: Will guide you to create an package. json file, including name, version, author and so on
16. npm root: View the installation path of the current package
npm root-g: View the installation path of the global package
17. npm-v: View the installed version of npm
For more commands, please refer to the official document of npm: https://www.npmjs.org/doc/