OSDN Git Service

Regular updates
[twpd/master.git] / npm.md
1 ---
2 title: npm
3 category: JavaScript
4 layout: 2017/sheet
5 weight: -1
6 updated: 2019-12-24
7 ---
8
9 ### Package management
10
11 | Command                           | Description                                               |
12 | ---                               | ---                                                       |
13 | `npm i`                           | Alias for `npm install`                                   |
14 | `npm install`                     | Install everything in package.json                        |
15 | `npm install --production`        | Install everything in package.json, except devDependecies |
16 | ---                               | ---                                                       |  
17 | `npm install lodash`              | Install a package                                         |
18 | `npm install --save-dev lodash`   | Install as devDependency                                  |
19 | `npm install --save-exact lodash` | Install with exact                                        |
20 | ---                               | ---                                                       |
21 | `npm version 1.2.3`               | Bump the package version to 1.2.3                         |
22 | `npm version major`               | Bump the major package version by 1 (1.2.3 → 2.0.0)       |
23 | `npm version minor`               | Bump the minor package version by 1 (1.2.3 → 1.3.0)       |
24 | `npm version patch`               | Bump the patch package version by 1 (1.2.3 → 1.2.4)       |
25
26
27 `--save` is the default as of npm@5. Previously, using `npm install` without `--save` doesn't update package.json.
28
29 ### Install names
30
31 | Command                              | Description             |
32 | ---                                  | ---                     |
33 | `npm i sax`                          | NPM package             |
34 | `npm i sax@latest`                   | Specify tag `latest`    |
35 | `npm i sax@3.0.0`                    | Specify version `3.0.0` |
36 | `npm i sax@">=1 <2.0"`               | Specify version range   |
37 | ---                                  | ---                     |
38 | `npm i @org/sax`                     | Scoped NPM package      |
39 | ---                                  | ---                     |
40 | `npm i user/repo`                    | GitHub                  |
41 | `npm i user/repo#master`             | GitHub                  |
42 | `npm i github:user/repo`             | GitHub                  |
43 | `npm i gitlab:user/repo`             | GitLab                  |
44 | ---                                  | ---                     |
45 | `npm i /path/to/repo`                | Absolute path           |
46 | `npm i ./archive.tgz`                | Tarball                 |
47 | `npm i https://site.com/archive.tgz` | Tarball via HTTP        |
48
49 ### Listing
50
51 | Command                 | Description                                                         |
52 | ---                     | ---                                                                 |
53 | `npm list`              | Lists the installed versions of all dependencies in this software   | 
54 | `npm list -g --depth 0` | Lists the installed versions of all globally installed packages     | 
55 | `npm view`              | Lists the latest versions of all dependencies in this software      | 
56 | `npm outdated`          | Lists only the dependencies in this software which are outdated     |
57
58 ### Updating
59
60 | Command             | Description                |
61 | ---                 | ---                        |
62 | `npm update`        | Update production packages |
63 | `npm update --dev`  | Update dev packages        |
64 | `npm update -g`     | Update global packages     |
65 | ---                 | ---                        |
66 | `npm update lodash` | Update a package           |
67
68
69 ### Removing
70
71 | Command             | Description                        |
72 | ---                 | ---                                |
73 | `npm rm lodash`     | Remove package production packages |
74
75 ### Misc features
76
77 ```bash
78 # Add someone as an owner
79 npm owner add USERNAME PACKAGENAME
80 ```
81
82 ```bash
83 # list packages
84 npm ls
85 ```
86
87 ```bash
88 # Adds warning to those that install a package of old versions
89 npm deprecate PACKAGE@"< 0.2.0" "critical bug fixed in v0.2.0"
90 ```
91
92 ```bash
93 # update all packages, or selected packages
94 npm update [-g] PACKAGE
95 ```
96
97 ```bash
98 # Check for outdated packages
99 npm outdated [PACKAGE]
100 ```