NPM Common Command parsing

Source: Internet
Author: User
Tags node server

What is NPM?

The full name of NPM is node Package Manager, which is a bundle management and distribution tool installed with Nodejs, which makes it easy for JavaScript developers to download, install, upload, and manage installed packages.

NPM Install module

Basic syntax

NPM install (with no args, in package dir) npm install [< @scope >/]<name>npm install [< @scope >/]<name& GT;@<TAG>NPM Install [< @scope >/]<name>@<version>npm install [< @scope >/]<name>@ <version range>npm Install <tarball file>npm install <tarball url>npm Install <FOLDER>ALIAS:NPM Icommon options: [-s|--save|-d|--save-dev|-o|--save-optional] [-e|--save-exact] [--dry-run]

Install package, the latest version is installed by default

NPM Install Gulp

Install the specified version

NPM install [email protected]

Install the package and keep the information in the project's Package.json file

The dependencies of a project on a module can be represented using the following 3 methods (assuming the current version number is 1.1.0):

    • Compatible modules newly released patch versions: ~1.1.0, 1.1.x, 1.1
    • Compatible modules new releases, patch versions: ^1.1.0, 1.x, 1
    • Compatibility module New release of the large version, iteration, patch version: *, X

-S,--save installation package information will be added to dependencies (dependent on production phase)

NPM Install Gulp--save or NPM install Gulp-s

Dependencies field of the Package.json file:

"Dependencies": {    "gulp": "^3.9.1"}

-D,--save-dev installation package information will be added to the devdependencies (development phase dependency), so the development phase typically uses it

NPM Install Gulp--save-dev or NPM install gulp-d

Devdependencies field of the Package.json file:

"Devdependencies": {    "gulp": "^3.9.1"}

-O,--save-optional installation package information will be added to Optionaldependencies (dependent on optional phase)

NPM Install Gulp--save-optional or NPM install Gulp-o

Optionaldependencies field of the Package.json file:

"Optionaldependencies": {    "gulp": "^3.9.1"},

-E,--save-exact precise installation of the specified module version

NPM Install Gulp--save-exact or NPM install GULP-E

Enter the command NPM install gulp-es, and note the Dependencies field of the Package.json file to see that the ^ in the version number disappears.

"Dependencies": {    "gulp": "3.9.1"}

module dependencies are written to the Package.json file, others open the project's root directory (project open source, internal team collaboration), and use the NPM Install command to install all dependent packages based on the dependencies configuration

NPM Install

Locally installed (local)

NPM Install Gulp

Global installation, using-G or--global

NPM Install Gulp-g
NPM LS View installed modules

Basic syntax

NPM ls [[< @scope >/]<pkg> ...] Aliases:list, LA, LL

View the globally installed modules and dependencies

NPM Uninstall Unload module

Basic syntax

NPM uninstall [< @scope >/]<pkg>[@<version>] ... [-s|--save|-d|--save-dev|-o|--save-optional]aliases:remove, RM, R, UN, unlink

such as uninstalling the development version of the module

NPM Uninstall Gulp--save-dev
NPM Update Updates Module

Basic syntax

NPM Update [-G] [<pkg> ....]
NPM outdated check if the module is obsolete

Basic syntax

NPM outdated [[< @scope >/]<pkg> ...]

This command lists all outdated packages that can be updated with the package in a timely manner

NPM Init creates a Package.json file in the project

The information about the installation package can be maintained in the project's Package.json file for subsequent project development or collaboration with others, and Package.json is essential in the project.

NPM Init [-f|--force|-y|--yes]

NPM Help view the details of a command

For example, enternpm help install,系统在默认的浏览器或者默认的编辑器中打开本地nodejs安装包的文件/nodejs/node_modules/npm/html/doc/cli/npm-install.html

NPM Help <command>
NPM RootTo view the installation path for a package

Path to Output node_modules

NPM Root [-g]
NPM configManaging the configuration path for NPM

Basic syntax

NPM config set <key> <value> [-g|--global]npm config get <key>npm config Delete <key>npm config li STNPM config editnpm get <key>npm set <key> <value> [-g|--global]

For config this block should be the most used to set up the agent, to solve the NPM installation of some modules failed problems

For example, I am in the company intranet, because of the company's firewall reasons, unable to complete any module installation, this time the setup agent can solve

NPM Config set proxy=http://dev-proxy.oa.com:8080

Also such as the domestic network environment problem, an official IP may be harmonious, fortunately, there are good people in the country, set up a mirror, at this time we have a simple setup mirror

NPM config set registry= "http://r.cnpmjs.org"
The cache of the NPM cache management module

Basic syntax

NPM Cache Add <tarball file>npm cache add <folder>npm cache add <tarball url>npm cache add <name>@ <VERSION>NPM cache ls [<path>]npm cache clean [<path>]

The most common command is to clear the NPM local cache

NPM Cache Clean
NPM Start Starter Module

Basic syntax

NPM start [--<args>]

This command is written in the Start field of the Package.json file scripts, and you can customize the command to configure a server environment and install a series of necessary programs, such as

"Scripts": {    "start": "Gulp-s"}

If the Package.json file is not set to start, node Server.js will be started directly

NPM Stop Stop Module

Basic syntax

NPM Stop [--<args>]
NPM Restart reboot Module

Basic syntax

NPM restart [--<args>]
About the syntax of NPM Package.json

You can refer to the NPM Package.json Chinese document, which is written in great detail.

Resources:

https://docs.npmjs.com/

1190000004221514

Https://cnodejs.org/getstart

Recently in understanding node. js. Found this post very useful, reproduced in http://www.cnblogs.com/PeunZhang/p/5553574.html

NPM Common Command parsing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.