index rss mastodon twitter github linkedin email
Álvaro Ramírez
sponsor

Álvaro Ramírez

30 December 2015 npm basics

Global vs local package installation location

{prefix}/lib/node_modules

vs

path/to/project/node_modules

View npm config

npm config list
; cli configs
user-agent = "npm/2.14.2 node/v4.0.0 darwin x64"

; node bin location = /Users/user/.nvm/versions/node/v4.0.0/bin/node
; cwd = /Users/user/stuff/active/blog
; HOME = /Users/user
; 'npm config ls -l' to show all defaults.

Get config value

npm config get prefix
/Users/user/.nvm/versions/node/v4.0.0

Set config value

npm config set prefix=$HOME/some/location

Install package globally

node install --global <package-name>

or

node install -g <package-name>

List global packages

npm list --global

You can also use –depth=0 to make less verbose.

/Users/user/.nvm/versions/node/v4.0.0/lib
├─┬ babel-eslint@4.1.3
│ ├── acorn-to-esprima@1.0.4
│ ├─┬ babel-core@5.8.25
│ │ ├── babel-plugin-constant-folding@1.0.1
│ │ ├── babel-plugin-dead-code-elimination@1.0.2
...

Install local package

npm install <package-name> --save

–save will add <package-name> dependency to your package.json.

package.json

Uninstall package

npm uninstall <package-name>

Install package at version

npm install <package-name>@1.7.0

Search packages

npm search linter

Online documentation

Online documentation is great so far. More at docs.npmjs.com.