A Brief Analysis of Common Commands of Nodejs npm

  • 2021-06-28 11:11:50
  • OfStack

npm is an node package management and distribution tool and has become an unofficial standard for publishing node modules (packages).With npm, packages for a particular service can be quickly found, downloaded, installed, and managed.

1. npm install moduleNames: Install the Node module

An node_will be generated after installationThe modules directory, under which each node module is installed.

node installation is divided into global mode and local mode.
1 Normally it runs in local mode and the package is installed to the local node_of your application codeUnder the modules directory.

In global mode, the Node package is installed in the node_installation directory of Nodemodules.

The global installation command is npminstall −gmoduleName.Known to use npminstall −gmoduleName.Learned to use 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 is installed by default, or a specified version, such as npm install, can be installed by adding a version number laterexpress@3.0.6

npm install < name > -g

Install package into global environment

However, there is no way to call globally installed packages directly from require () in your code.A global installation is for the command line, as if vmarket had been installed globally, then the vm command could be run directly from the command line

npm install < name > --save
When installing, writing information to the project path in package.json, if there is an package.json file, you can use the npm install method directly to

The dependencies configuration installs all dependent packages so that when code is submitted to github, node_does not have to be submittedThis folder is modules.

2. npm view moduleNames: View the package.json folder of the node module

Important: If you want to view the contents 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
Important: The Node module search starts from the current directory where the code is executed, and the search results depend on the node_in the directory currently in useContents under modules. $npm list parseable=true can present all currently installed node packages as a catalog

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 on which the package depends

8. npm help folders: View all folders used by npm

9. npm rebuild moduleName: Used for rebuilding after changing package contents

10, npm outdated: Check if the package is obsolete. This command lists all obsolete packages and updates them in time

11. npm update moduleName: Update node module

12. npm uninstall moudleName: Uninstall the node module

13. An npm package is a folder containing package.json, the structure of which is described by package.json.Access the json folder of npm is as follows:

$ npm help json

This command opens a Web page by default and may not open as a Web page if the default open program is changed.

14. When publishing an npm package, you need to verify that a package name already exists

$ npm search packageName

15, npm init: This will lead you to create an package.json file, including name, version, author information, etc.

16, npm root: View the installation path of the current package

npm root - g: View the global package installation path

17. npm - v: View the version installed by npm


Related articles: