NPM common commands (11)

Table of contents

1、npm shrinkwrap

1.1 Use syntax

1.2 Description

2、npm star

2.1 Use syntax

2.1 Description

3、npm stars

3.1 Use syntax

3.2 Description

4、npm start

4.1 Using syntax

4.2 Description

 5、npm stop

5.1 Using syntax

5.2 Description

6、npm team

6.1 Using syntax

6.2 Description

6.3 Details

7、npm test

7.1 Using syntax

7.2 Description

8、npm token

8.1 Using syntax

8.2 Description

9、npm uninstall

9.1 Using syntax

9.2 Description

9.3 Example


1、npm shrinkwrap

1.1 Use syntax

npm shrinkwrap

1.2 Description

This command is used to lock the published dependency version.

This command will repurpose package-lock.json into a publishable npm-shrinkwrap.json or simply create a new one. Files created and updated by this command will take precedence over any other existing or future package-lock.json files.

2、npm star

2.1 Use syntax

npm star [<package-spec>...]

2.1 Description

This command can be used to mark your favorite packages. On the corresponding git warehouse page, you can see the corresponding star number.

3、npm stars

3.1 Use syntax

npm stars [<user>]

3.2 Description

This command can view packages marked as favorites.

If you've starred a lot of neat things and want to quickly find them again, this command lets you do that.

4、npm start

4.1 Using syntax

npm start [-- <args>]

4.2 Description

This will run the predefined command specified in the  attribute of the package's "scripts" object. "start"

If the "scripts" object does not define the "start" property, npm will run node server.js.

Note that this is different from the default node behavior of running files specified in the  attribute of the package when called with node . . "main"

Example:

{
  "scripts": {
    "start": "node foo.js"
  }
}

 5、npm stop

This command is used to stop a package

5.1 Using syntax

npm stop [-- <args>]

5.2 Description

This will run the predefined command specified in the "stop" attribute of the package's "scripts" object.

is different from npm startnpm startnpm start , If the "stop" attribute is not defined, the default script will not be run.

{
  "scripts": {
    "stop": "node bar.js"
  }
}

6、npm team

This command is used to manage organizational teams and team membership.

6.1 Using syntax

npm team create <scope:team> [--otp <otpcode>]
npm team destroy <scope:team> [--otp <otpcode>]
npm team add <scope:team> <user> [--otp <otpcode>]
npm team rm <scope:team> <user> [--otp <otpcode>]
npm team ls <scope>|<scope:team>

6.2 Description

Used to manage teams in an organization, and to change team members. Does not handle package permissions.

Teams must always operate on them in full compliance with the organization/scope they belong to, separated by a colon (:). That is, if you have a  team in a org organization, you must always refer to that team as . newteam@org:newteam

If you have two-factor authentication enabled in auth-and-writes mode, you can use [--otp <otpcode>] to provide the code from the authenticator. If you don't include this, then you will be taken to the second factor flow based on your authtype .

  • create / destroy: Create a new team, or destroy an existing team. NOTE: You cannot delete developers teams

    Here's how to create a new team  under the org organization: newteam

npm team create @org:newteam
  • add: Add a user to an existing team.

        Add new user username to team named  in org organization: newteam

npm team add @org:newteam username

Upon success, you should see a message: username added to @org:newteam

  • rm: Using npm team rm you can also remove users from the teams they belong to.

    This is an example of removing a user  from a  team in the org organization: newteamusername

npm team rm @org:newteam username

After deleting a user, a confirmation message will be displayed: username removed from @org:newteam

  • ls: If executed on an organization name, will return a list of existing teams under that organization. If executed against a team, it will return a list of all users belonging to that specific team.

Here's an example of how to list all teams from an organization named org :

npm team ls @org

Example listing all members of a team named newteam :

npm team ls @org:newteam

6.3 Details

npm team always runs directly on the current registry and can be configured from the command line using --registry=<registry url> .

You must be a team administrator to create teams and manage team membership under a given organization. Listing teams and team memberships can be completed by any member of the organization.

Organization creation and management for team admins and organization members is done through the website, not the npm CLI.

To use teams to manage permissions for packages belonging to your organization, use the npm access command to grant or revoke the appropriate permissions.

7、npm test

This command is used to test a package.

7.1 Using syntax

npm test [-- <args>]

别名: tst, t

7.2 Description

This will run the predefined command specified in the  attribute of the package's "scripts" object. "test"

Example:

{
  "scripts": {
    "test": "node test.js"
  }
}

8、npm token

This command is used to manage your authentication tokens

8.1 Using syntax

npm token list
npm token revoke <id|token>
npm token create [--read-only] [--cidr=list]

8.2 Description

This allows you to list, create and revoke authentication tokens.

  • npm token list: Table showing all active authentication tokens. You can request it as JSON with --json or as tab-separated value with --parseable .
+--------+---------+------------+----------+----------------+
| id     | token   | created    | read-only | CIDR whitelist |
+--------+---------+------------+----------+----------------+
| 7f3134 | 1fa9ba… | 2017-10-02 | yes      |                |
+--------+---------+------------+----------+----------------+
| c03241 | af7aef… | 2017-10-02 | no       | 192.168.0.1/24 |
+--------+---------+------------+----------+----------------+
| e0cf92 | 3a436a… | 2017-10-02 | no       |                |
+--------+---------+------------+----------+----------------+
| 63eb9d | 74ef35… | 2017-09-28 | no       |                |
+--------+---------+------------+----------+----------------+
| 2daaa8 | cbad5f… | 2017-09-26 | no       |                |
+--------+---------+------------+----------+----------------+
| 68c2fe | 127e51… | 2017-09-23 | no       |                |
+--------+---------+------------+----------+----------------+
| 6334e1 | 1dadd1… | 2017-09-23 | no       |                |
+--------+---------+------------+----------+----------------+

Open the corresponding token through the page, as shown below:

  • npm token create [--read-only] [--cidr=<cidr-ranges>]: Create a new authentication token. It can be --read-only, or accept a list of CIDR
     ranges to restrict use of this token. This will prompt you for your password, or your password if you have two-factor authentication enabled.
+----------------+--------------------------------------+
| token          | a73c9572-f1b9-8983-983d-ba3ac3cc913d |
+----------------+--------------------------------------+
| cidr_whitelist |                                      |
+----------------+--------------------------------------+
| readonly       | false                                |
+----------------+--------------------------------------+
| created        | 2017-10-02T07:52:24.838Z             |
+----------------+--------------------------------------+
  • npm token revoke <token|id>: Immediately removes the authentication token from the registry. You will no longer be able to use it. This can accept full tokens (such as the token you returned from npm token create and the token found in your .npmrc ), as well as the token found in  output. npm token list id that can be parsed or seen in json output. This will not accept truncation tags found in normal npm token list

9、npm uninstall

This command is used to uninstall the installation package

9.1 Using syntax

npm uninstall [<@scope>/]<pkg>...

aliases: unlink, remove, rm, r, un

9.2 Description

This will uninstall a package, completely removing the npm package it installed.

它还会从 package.json 中訳 dependencies, devDependencies, optionalDependencies 和 peerDependencies 对子中删开壳.

Also, if you have npm-shrinkwrap.json or package-lock.json , npm will update those files as well.

--no-save will tell npm not to remove the package from your package.json, npm-shrinkwrap.json or package-lock.json files.

--save or -S will tell npm to retrieve data from your package.json , npm-shrinkwrap.json and package-lock.json Delete the package from the file. This is the default, but you may want to use it if your npmrc file has for example save=false

In global mode (that is, appending -g or --global to the command), it unloads the current package context as a global package. In this case, --no-save is ignored.

9.3 Example

npm uninstall benchmark

The benchmark will no longer appear in your package.json, npm-shrinkwrap.json or package-lock.json files.

npm uninstall benchmark --no-save

benchmark will not be deleted from your package.json, npm-shrinkwrap.json or package-lock.json files.

Guess you like

Origin blog.csdn.net/u014388408/article/details/133683015