Differences between revisions 3 and 4
Revision 3 as of 2023-01-08 17:19:29
Size: 1617
Comment:
Revision 4 as of 2023-01-08 17:25:55
Size: 1419
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
## page was renamed from Node/NPM
## page was renamed from NodeJS/NPM
Line 5: Line 3:
'''`npm(1)`''' is the package manager for the NodeJS ecosystem. It is bundled with `node(1)`, though note that it is developed independently and version numbers differ. '''`npm(1)`''' ('''Node Package Manager''') is a package manager for third-party Node modules.

See also [[Node/Yarn|yarn]] and [[Node/Npx|npx]].
Line 13: Line 13:
== Installation ==

`npm(1)` is bundled with `node(1)`.

----

Line 15: Line 22:
=== Local Installation === Modules can be installed ''locally'' or ''globally''.
Line 17: Line 24:
Local installation is the default for `npm(1)`. A `node_modules` directory will be created under the current working directory. Packages will be installed to `./node_modules`, and binaries will be installed to `./node_modules/bin`. Local installation uses `./node_modules` for modules and `./node_modules/bin` for binaries. This is the default behavior.
Line 19: Line 26:
{{{
npm install jquery
}}}
Line 20: Line 30:
Global installation uses `$NPM_CONFIG_PREFIX/lib/node_modules` for modules and `$NPM_CONFIG_PREFIX/bin` for binaries. To enable this mode, include the `--global` flag (or `-g` for short).
Line 21: Line 32:
=== Global Installation === {{{
npm install jquery -g
}}}
Line 23: Line 36:
Global installation can be toggled on using the `--global` option. Packages will be installed to `$NPM_CONFIG_PREFIX/lib/node_modules`, and binaries will be installed to `$NPM_CONFIG_PREFIX/bin`. If `$NPM_CONFIG_PREFIX` is not set, the default can be inspected using:
Line 25: Line 38:
If `$NPM_CONFIG_PREFIX` is unset, installation defaults to: {{{
NPM_CONFIG_PREFIX= npm prefix -g
}}}
Line 27: Line 42:
 * `%APPDATA%\npm` on Windows
 * `/usr/local` on some Linux distributions, `/usr` on others

You can check the current installation target using `npm prefix -g`.
For more details, see [[NodeJS/NPM|here]].
Line 38: Line 50:
`npm(1)` uses many environment variables for configuration, all prefixed with `NPM_CONFIG_`. `npm(1)` uses environment variables for configuration, all prefixed with `NPM_CONFIG_`.
Line 40: Line 52:
||'''Variable''' ||'''Default''' ||'''Function''' ||
||`NPM_CONFIG_PREFIX` ||see above ||changes the global installation directory ||
||`NPM_CONFIG_CACHE` ||`~/.npm`, `%APPDATA%/npm-cache` ||changes the package cache directory ||
||`NPM_CONFIG_DEVDIR` ||`~/.node-gyp` ||changes the native addon build directory ||
||'''Variable''' ||'''Default''' ||'''Meaning''' ||
||`NPM_CONFIG_PREFIX` ||see above ||global installation directory ||
||`NPM_CONFIG_CACHE` ||`~/.npm`, `%APPDATA%/npm-cache` ||package cache directory ||
||`NPM_CONFIG_DEVDIR` ||`~/.node-gyp` ||native addon build directory ||

NPM

npm(1) (Node Package Manager) is a package manager for third-party Node modules.

See also yarn and npx.


Installation

npm(1) is bundled with node(1).


Usage

Modules can be installed locally or globally.

Local installation uses ./node_modules for modules and ./node_modules/bin for binaries. This is the default behavior.

npm install jquery

Global installation uses $NPM_CONFIG_PREFIX/lib/node_modules for modules and $NPM_CONFIG_PREFIX/bin for binaries. To enable this mode, include the --global flag (or -g for short).

npm install jquery -g

If $NPM_CONFIG_PREFIX is not set, the default can be inspected using:

NPM_CONFIG_PREFIX= npm prefix -g

For more details, see here.


Configuration

npm(1) uses environment variables for configuration, all prefixed with NPM_CONFIG_.

Variable

Default

Meaning

NPM_CONFIG_PREFIX

see above

global installation directory

NPM_CONFIG_CACHE

~/.npm, %APPDATA%/npm-cache

package cache directory

NPM_CONFIG_DEVDIR

~/.node-gyp

native addon build directory


CategoryRicottone

Node/Npm (last edited 2023-04-08 17:34:36 by DominicRicottone)