2013-10-14 02:36:58 +00:00
|
|
|
---
|
|
|
|
title: npm
|
2015-11-24 04:48:01 +00:00
|
|
|
category: JavaScript
|
2017-10-27 04:29:55 +00:00
|
|
|
weight: -1
|
2020-07-04 13:33:09 +00:00
|
|
|
updated: 2019-12-24
|
2013-10-14 02:36:58 +00:00
|
|
|
---
|
|
|
|
|
2017-10-27 04:29:55 +00:00
|
|
|
### Package management
|
2014-02-25 10:32:14 +00:00
|
|
|
|
2019-11-04 12:04:08 +00:00
|
|
|
| Command | Description |
|
|
|
|
| --- | --- |
|
|
|
|
| `npm i` | Alias for `npm install` |
|
|
|
|
| `npm install` | Install everything in package.json |
|
|
|
|
| `npm install --production` | Install everything in package.json, except devDependecies |
|
2024-04-03 07:30:24 +00:00
|
|
|
|
|
|
|
### Adding packages
|
|
|
|
|
|
|
|
| Command | Description |
|
2019-11-04 12:04:08 +00:00
|
|
|
| --- | --- |
|
|
|
|
| `npm install lodash` | Install a package |
|
|
|
|
| `npm install --save-dev lodash` | Install as devDependency |
|
|
|
|
| `npm install --save-exact lodash` | Install with exact |
|
2014-02-25 10:32:14 +00:00
|
|
|
|
2019-11-04 12:04:08 +00:00
|
|
|
### Listing
|
2019-12-24 11:03:49 +00:00
|
|
|
|
2019-11-04 12:04:08 +00:00
|
|
|
| Command | Description |
|
|
|
|
| --- | --- |
|
|
|
|
| `npm list` | Lists the installed versions of all dependencies in this software |
|
|
|
|
| `npm list -g --depth 0` | Lists the installed versions of all globally installed packages |
|
|
|
|
| `npm view` | Lists the latest versions of all dependencies in this software |
|
|
|
|
| `npm outdated` | Lists only the dependencies in this software which are outdated |
|
|
|
|
|
2017-10-27 04:29:55 +00:00
|
|
|
### Updating
|
2014-02-25 10:32:14 +00:00
|
|
|
|
2017-10-27 04:29:55 +00:00
|
|
|
| Command | Description |
|
|
|
|
| --- | --- |
|
|
|
|
| `npm update` | Update production packages |
|
|
|
|
| `npm update --dev` | Update dev packages |
|
|
|
|
| `npm update -g` | Update global packages |
|
|
|
|
| --- | --- |
|
|
|
|
| `npm update lodash` | Update a package |
|
2014-02-25 10:32:14 +00:00
|
|
|
|
|
|
|
|
2022-11-01 03:13:32 +00:00
|
|
|
### Removing
|
|
|
|
|
|
|
|
| Command | Description |
|
|
|
|
| --- | --- |
|
|
|
|
| `npm rm lodash` | Remove package production packages |
|
|
|
|
|
2024-04-03 07:30:24 +00:00
|
|
|
## More features
|
|
|
|
|
|
|
|
### Install names
|
|
|
|
|
|
|
|
| Command | Description |
|
|
|
|
| --- | --- |
|
|
|
|
| `npm i sax` | NPM package |
|
|
|
|
| `npm i sax@latest` | Specify tag `latest` |
|
|
|
|
| `npm i sax@3.0.0` | Specify version `3.0.0` |
|
|
|
|
| `npm i sax@">=1 <2.0"` | Specify version range |
|
|
|
|
| --- | --- |
|
|
|
|
| `npm i @org/sax` | Scoped NPM package |
|
|
|
|
| --- | --- |
|
|
|
|
| `npm i user/repo` | GitHub |
|
|
|
|
| `npm i user/repo#master` | GitHub |
|
|
|
|
| `npm i github:user/repo` | GitHub |
|
|
|
|
| `npm i gitlab:user/repo` | GitLab |
|
|
|
|
| --- | --- |
|
|
|
|
| `npm i /path/to/repo` | Absolute path |
|
|
|
|
| `npm i ./archive.tgz` | Tarball |
|
|
|
|
| `npm i https://site.com/archive.tgz` | Tarball via HTTP |
|
|
|
|
|
|
|
|
### Bumping versions
|
|
|
|
|
|
|
|
| Command | Description |
|
|
|
|
| --- | --- |
|
|
|
|
| `npm version 1.2.3` | Bump the package version to 1.2.3 |
|
|
|
|
| `npm version major` | Bump the major package version by 1 (1.2.3 → 2.0.0) |
|
|
|
|
| `npm version minor` | Bump the minor package version by 1 (1.2.3 → 1.3.0) |
|
|
|
|
| `npm version patch` | Bump the patch package version by 1 (1.2.3 → 1.2.4) |
|
|
|
|
|
2017-10-27 04:29:55 +00:00
|
|
|
### Misc features
|
2016-08-29 16:17:18 +00:00
|
|
|
|
2017-10-27 04:29:55 +00:00
|
|
|
```bash
|
|
|
|
# Add someone as an owner
|
|
|
|
npm owner add USERNAME PACKAGENAME
|
|
|
|
```
|
|
|
|
|
|
|
|
```bash
|
|
|
|
# list packages
|
|
|
|
npm ls
|
|
|
|
```
|
|
|
|
|
|
|
|
```bash
|
|
|
|
# Adds warning to those that install a package of old versions
|
|
|
|
npm deprecate PACKAGE@"< 0.2.0" "critical bug fixed in v0.2.0"
|
|
|
|
```
|
|
|
|
|
|
|
|
```bash
|
|
|
|
# update all packages, or selected packages
|
|
|
|
npm update [-g] PACKAGE
|
|
|
|
```
|
|
|
|
|
|
|
|
```bash
|
|
|
|
# Check for outdated packages
|
|
|
|
npm outdated [PACKAGE]
|
|
|
|
```
|