eolas/Programming_Languages/NodeJS/Modules/Package_management.md

38 lines
1.7 KiB
Markdown
Raw Normal View History

2022-04-23 13:26:53 +01:00
---
tags:
- Programming_Languages
- backend
- node-js
- npm
---
2022-07-16 10:30:04 +01:00
# Package management
2022-04-23 13:26:53 +01:00
## List installed packages
2022-07-16 10:30:04 +01:00
```bash
2022-04-23 13:26:53 +01:00
npm list
2022-07-16 10:30:04 +01:00
```
This will return a recursive tree that lists dependencies, dependences of dependencies, ... and so on.
2022-04-23 13:26:53 +01:00
To limit the depth you can add the `--depth=` flag. For example to see only your installed packages and their versions use `npm list --depth=0`.
## View `package.json` data for an installed package
We could go to the NPM registry and view details or we can quickly view the `package.json` for the dependency with the command `npm view [package_name]`
We can pinpoint specific dependencies in the `package.json`, e.g. `npm view [package_name] dependencies `
## View outdated modules
See whether your dependency version is out of date use `npm outdated`. This gives us a table, for example:
2022-07-16 10:30:04 +01:00
![Pasted image 20220411082627.png](/img/Pasted_image_20220411082627.png)
2022-04-23 13:26:53 +01:00
* *Latest* tells us the latest release available from the developers
* *Wanted* tells us the version that our `package.json` rules target. To take the first dependency as an example. We must have set our SemVer syntax to `^0.4.x` since it is telling us that there is a minor release that is more recent than the one we have installed but is not advising that we update to the latest major release.
* *Current* tells us which version we currently have installed regardless of the version that our `package.json` is targeting or the most recent version available.
## Updating
2022-07-16 10:30:04 +01:00
`npm update` only updates from *current* to *wanted*. In other words it only updates in accordance with your caret and tilde rules applied to [semantic versioning](/Software_Engineering/Semantic_versioning.md).