What is npm
The full name of NPM is Node Package Manager, which is a package management and distribution tool installed with NodeJS. It is very convenient for JavaScript developers to download, install, upload and manage installed packages.
npm is a node package management and distribution tool, and has become the unofficial standard for releasing node modules (packages). With npm, you can quickly find the packages to use for a specific service, download, install and manage the installed packages.
1. npm install moduleNames: install Node module
After installation, a node_modules directory will be generated, and the various node modules installed are in the directory.
The installation of node is divided into global mode and local mode.
Generally, it will run in local mode, and the package will be installed in the local node_modules directory of your application code.
In global mode, the Node package will be installed under node_modules in the Node installation directory.
The global installation command is $npm install -g moduleName.
You know that you use $npm set global=true to set the installation mode, and $npm get global can view the currently used installation mode.
Example:
The code copy is as follows:
npm install express
The latest version of express will be installed by default, and you can also install the specified version by adding a version number later, such as npm install [email protected]
The code copy is as follows:
npm install <name> -g
Install the package into the global environment
However, in the code, there is no way to call globally installed packages directly through require(). The global installation is for the command line, just like after installing vmarket globally, you can run the vm command directly in the command line.
The code copy is as follows:
npm install <name> --save
While installing, write information to the project path in package.json. If there is a package.json file, you can directly use the npm install method to install all dependencies according to dependencies configuration. In this way, when the code is submitted to github, you do not need to submit the node_modules folder.
2. npm view moduleNames: view the package.json folder of the node module
Note: If you want to view the content of a label under the package.json folder, you can use $npm view moduleName labelName
3. npm list: view the installed node packages in the current directory
Note: Node module search starts from the current directory where the code is executed, and the search results depend on the content under node_modules in the currently used directory. $ npm list parseable=true can be used as a directory to display all currently installed
node package
4. npm help: view the help command
5. npm view moudleName dependencies: view the dependencies of the package
6. npm view moduleName repository.url: view the source file address of the package
7. npm view moduleName engines: view the version of the 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 the package contents
10. npm outdated: Check whether the package is outdated. This command will list all outdated packages and can update the package in time.
11. npm update moduleName: update node module
12. npm uninstall buttonName: uninstall node module
13. An npm package is a folder containing package.json. package.json describes the structure of this folder. The method to access npm's json folder is as follows:
The code copy is as follows:
$ npm help json
This command opens a web page in the default way, and may not be opened as a web page if you change the default opening program.
14. When publishing an npm package, you need to check whether a package name already exists.
The code copy is as follows:
$ npm search packageName
15. npm init: will guide you to create a package.json file, including name, version, author and other information.
16. npm root: Check the installation path of the current package
npm root -g: Check the installation path of the global package
17. npm -v: View the version of npm installed
For more commands, please refer to the official npm document: https://www.npmjs.org/doc/
The above is a detailed explanation of the commonly used npm commands in Nodejs introduced to you by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support to Wulin.com website!