Benutzer:Andreas Plank/npm

Aus Offene Naturführer
Wechseln zu: Navigation, Suche

https://www.sitepoint.com/beginners-guide-node-package-manager/

Note, that npm is separate from Node.js and with nvm one can install multiple versions of Node.js

Common Commands

npm help

… or a brief list of some of the commonly used npm aliases:

  • npm i package – install local package
  • npm i -g package package – install global package
  • npm un package package – uninstall local package
  • npm up – npm update packages
  • npm t – run tests
  • npm ls – list installed modules
  • npm ll or npm la – print additional package information while listing modules
# search a package
npm search mkdir

# show config variables
npm config list

# update to the latest npm ?globally
npm install npm@latest -g

# to save explicitly the dependency in package.json
npm install package --save

# check for outdated packages
npm outdated

Check for security vulnerabilities: audit

# example
npm install express@4.8.0
# express@4.8.0
# added 36 packages from 24 contributors and audited 123 packages in 15.97s
# found 21 vulnerabilities (8 low, 9 moderate, 4 high)
#   run `npm audit fix` to fix them, or `npm audit` for details

# show and report vulnerabilities
npm run audit
#   it may report to install a higher version so one could run
#     npm install express@4.16.4 
#   as the report may have suggested, or run 
#     npm audit 
#   to fix it

# if you don’t mind upgrading packages with breaking changes, run
npm audit fix --force


Package Versioning and Managing

# list package cache and things 
ls ~/.npm
# anonymous-cli-metrics.json  _cacache  index-v5  _locks  _logs  node-sass
# This directory will get cluttered with old packages over time, so it’s useful 
# to clean it up occasionally.
npm cache clean --force

# clean downloaded packages in *all* node_modules folders that it can find
find . -name "node_modules" -type d -exec rm -rf '{}' +

Semantic Versioning

scheme major.minor.patch, e.g. 2.1.4

  • start version: 0.1.0
  • before 1.0.0 is only developmental mode

Node.js using nvm

https://www.sitepoint.com/quick-tip-multiple-versions-node-nvm/

List installed instances

nvm ls

Switch Versions

# switch to Node.js version 8.9.4
nvm use 8.9.4
# switch to Node.js version 9.3.0
nvm use 9.3
# switch to latest Node.js version
nvm use node
# switch to latest LTS Node.js version
nvm use node --lts

Uninstall

nvm uninstall 0.11
Quelle: Offene Naturführer, Das Wiki zu Bestimmungsfragen: Benutzer:Andreas Plank/npm (Zuletzt geändert:
Dieses Attribut ist ein Spezialattribut in diesem Wiki.
5 November 2019 13:36:44). Abgerufen am 21. Dezember 2024, 20:00 von https://offene-naturfuehrer.de/web/Benutzer:Andreas_Plank/npm