This is the 13th day of my participation in Gwen Challenge

Introduce NPM

NPM is a package manager similar to PIP for Python. NPM is a package management tool installed with NodeJS.

How do I install NPM

Nodejs already integrates with NPM, so you only need to install NodeJS. After the installation, run the NPM -v command to check whether the installation is successful

Switch domestic TAOBAO NPM mirror

npm install -g cnpm –registry=registry.npm.taobao.org

Install modules using a domestic NPM image

CNPM install Specifies the module name

Upgrade NPM

Windows command: NPM install NPM -g

Linux: sudo NPM install NPM -g

Install modules using NPM

Grammar:

NPM install Specifies the module name

For example:

npm install express

After the Express module is installed, the Express package is stored in the node_moudules directory of the project directory. In the code, var express = require(‘express’); You can use modules.

Global installation and local installation

The local installation

NPM install Specifies the module name

Global installation

NPM install -g

Locally installed Modules

  1. /node_modules (the directory where the NPM command is run). If there is no node_modules directory, the node_modules directory will be generated in the directory where the NPM command is run.
  2. You can import locally installed packages by requiring (” module name “).

Global installation module

  1. Place the installation package in /usr/local or your Node installation directory.
  2. It can be used directly from the command line.

If you want to install both globally and locally, use both methods.

NPM Other common commands

View installation module information

View all installed modules globally:

npm list -g

or

npm ls

View the version number of a module

npm list grunt

Uninstall the module

NPM Uninstall Module name

The update module

The local update

NPM Update module name

A global update

NPM Update module name -g

Search module

NPM Search module name

Create a module

npm init

The package.json file is essential to creating the module. We can use NPM to generate package.json files that contain the basic results

Package.json property description

  • Name – Packet name.

  • Version – Indicates the package version number.

  • Description – The description of the packet.

  • Homepage – The official url of this package.

  • Author – The author name of the package.

  • Names of other contributors to the Ficolin-packs.

  • Dependencies – List of dependent packages. If the dependency package is not installed, NPM automatically installs the dependency package in the node_module directory.

  • Repository – The type of place where package code is stored. It can be git or SVN. Git is available on Github.

  • The main-main field specifies the program’s main entry file, which requires (‘moduleName’) loads. The default value for this field is index.js under the module root.

  • Keywords – Keywords

Publish module

npm publish

Unpublish module

NPM unpublish module name @ version number

Clear the cache

npm cache clear

If you think the blogger wrote good, welcome to “pay attention to, collect, like” three even one key!