Table of Contents

About

Npm is the package manager that is packaged/installed with a node installation.

Management

Installation

Update

To update npm self, execute the following statement:

npm install npm@latest -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 What are npm scripts and how to use them ? The script property of Package.json

Config

npm gets its config settings from:

  • the command line,
  • environment variables,

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

Heading Text Not found

npm config get registry
https://registry.npmjs.org/

Default Directory

npm config get prefix
C:\Users\foo\AppData\Roaming\npm

node-module

Prior to npm@3, 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 npm@3 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.

Documentation / Reference