Javascript - npm (Node package manager)
Table of Contents
About
Npm is the package manager that is packaged/installed with a node installation.
Articles Related
Management
Installation
- Automatically, with a node installation.
- Manually: https://registry.npmjs.org/npm/-/npm-{VERSION}.tgz
Update
To update npm self, execute the following statement:
npm install [email protected] -g
C:\Users\gerard\AppData\Roaming\npm\npm -> C:\Users\gerard\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js
C:\Users\gerard\AppData\Roaming\npm
`-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
........................
npx upgrade with npm
Version
npm -v
4.5.0
Script
See NPM - Script
Config
npm gets its config settings from:
- the command line,
- environment variables,
- and npmrc files.
The npm config command can be used to update and edit the contents of the user and global npmrc files.
Environment variable
Npm reads configuration from any environment variables beginning with NPM_CONFIG.
Config file ( .npmrc)
The .npmrc file is in your project’s root.
npm config get userconfig # defaults to ~/.npmrc
C:\Users\gerard\.npmrc
npm config get globalconfig # defaults to /usr/local/etc/npmrc
C:\Users\gerard\AppData\Roaming\npm\etc\npmrc
Registry
Default Directory
npm config get prefix
C:\Users\foo\AppData\Roaming\npm
node-module
Prior to [email protected], the node_modules dependency structure had its own node_modules folder with all of its dependencies specified in package.json.
node_modules
└─ foo
├─ index.js
├─ package.json
└─ node_modules
└─ bar
├─ index.js
└─ package.json
With [email protected] the node_modules structure is now flat:
node_modules
├─ foo
| ├─ index.js
| └─ package.json
└─ bar
├─ index.js
└─ package.json
Source code may require dependencies that are not added as dependencies to the project.