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
22 `--save` is the default as of npm@5. Previously, using `npm install` without `--save` doesn't update package.json.
23
24 ### Install names
25
26 | Command                              | Description             |
27 | ---                                  | ---                     |
28 | `npm i sax`                          | NPM package             |
29 | `npm i sax@latest`                   | Specify tag `latest`    |
30 | `npm i sax@3.0.0`                    | Specify version `3.0.0` |
31 | `npm i sax@">=1 <2.0"`               | Specify version range   |
32 | ---                                  | ---                     |
33 | `npm i @org/sax`                     | Scoped NPM package      |
34 | ---                                  | ---                     |
35 | `npm i user/repo`                    | GitHub                  |
36 | `npm i user/repo#master`             | GitHub                  |
37 | `npm i github:user/repo`             | GitHub                  |
38 | `npm i gitlab:user/repo`             | GitLab                  |
39 | ---                                  | ---                     |
40 | `npm i /path/to/repo`                | Absolute path           |
41 | `npm i ./archive.tgz`                | Tarball                 |
42 | `npm i https://site.com/archive.tgz` | Tarball via HTTP        |
43
44 ### Listing
45
46 | Command                 | Description                                                         |
47 | ---                     | ---                                                                 |
48 | `npm list`              | Lists the installed versions of all dependencies in this software   | 
49 | `npm list -g --depth 0` | Lists the installed versions of all globally installed packages     | 
50 | `npm view`              | Lists the latest versions of all dependencies in this software      | 
51 | `npm outdated`          | Lists only the dependencies in this software which are outdated     |
52
53 ### Updating
54
55 | Command             | Description                |
56 | ---                 | ---                        |
57 | `npm update`        | Update production packages |
58 | `npm update --dev`  | Update dev packages        |
59 | `npm update -g`     | Update global packages     |
60 | ---                 | ---                        |
61 | `npm update lodash` | Update a package           |
62
63
64 ### Misc features
65
66 ```bash
67 # Add someone as an owner
68 npm owner add USERNAME PACKAGENAME
69 ```
70
71 ```bash
72 # list packages
73 npm ls
74 ```
75
76 ```bash
77 # Adds warning to those that install a package of old versions
78 npm deprecate PACKAGE@"< 0.2.0" "critical bug fixed in v0.2.0"
79 ```
80
81 ```bash
82 # update all packages, or selected packages
83 npm update [-g] PACKAGE
84 ```
85
86 ```bash
87 # Check for outdated packages
88 npm outdated [PACKAGE]
89 ```