Nodejs npm common commands

https://www.cnblogs.com/jihequn/p/6026455.html

npm is a node package management and distribution tool that has become the unofficial standard for publishing node modules (packages). With npm, you can quickly find packages to be used by a specific service, download, install, and manage installed packages.

1. npm install moduleNames:
After installing the Node module, a node_modules directory will be generated, under which the installed node modules are located.

The installation of node is divided into global mode and local mode.
Normally running in local mode, packages are installed into the node_modules directory local to your application code.
In global mode, Node packages are installed under node_modules in the Node installation directory.

The global installation command is $npm install -g moduleName.
Know that $npm set global=true is used to set the installation mode, and $npm get global can view the currently used installation mode.

Example:
npm install express 
will install the latest version of express by default, or you can install the specified version by appending the version number, such as npm install [email protected]

npm install <name> -g 
installs the package into the global environment

But in the code, there is no way to call the globally installed package directly through require(). The global installation is for the command line, just like after vmarket is installed globally, you can run the vm command directly on the command line

npm install <name> --save 
at the same time of installation, write the information into the project path in package.json If there is a package.json file, you can directly use the npm install method to install all dependent packages according to the dependencies configuration, so that the code is submitted When you go to github, you don't need to submit the node_modules folder.

2. npm view moduleNames: View the package.json folder of the node module
Notes: If you want to view the content of a label in the package.json folder, you can use $npm view moduleName labelName

3. npm list: View the installed node packages in the current directory
Notes: 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 display all currently installed node packages in the form of a directory

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 the package content

10. npm outdated: Check whether the package is outdated, this command will list all outdated packages, and the package can be updated in time

11. npm update moduleName: update the node module

12. npm uninstall moduleName: uninstall node module

13、一个npm包是包含了package.json的文件夹,package.json描述了这个文件夹的结构。访问npm的json文件夹的方法如下:
$ npm help json 
此命令会以默认的方式打开一个网页,如果更改了默认打开程序则可能不会以网页的形式打开。

14、发布一个npm包的时候,需要检验某个包名是否已存在
$ npm search packageName

15、npm init:会引导你创建一个package.json文件,包括名称、版本、作者这些信息等

16、npm root:查看当前包的安装路径
npm root -g:查看全局的包的安装路径

17、npm -v:查看npm安装的版本

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325442767&siteId=291194637