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 npminstall−gmoduleName. Know that npminstall−gmoduleName is used. You know that using npm set global=true to set the installation mode, $npm get global can view the currently used installation mode.
Example:
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]
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.
npm install <name> --save
While installing, write information to the project path in package.json. If there is a package.json file, you can use the npm install method directly to follow
Dependencies configures to install all dependencies, so that when the code is submitted to github, there is no 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 node packages currently installed
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:
$ 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.
$ 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: View the installation path of global packages
17. npm -v: View the version of npm installed
The above is the full description of the commonly used commands for Nodejs npm introduced to you. 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!