Npm: Difference between revisions

From miki
Jump to navigation Jump to search
(Created page with "Npm is Node Package Manager, a tool to install Node.js package. == References == * https://www.npmjs.com/ == Quickstart == <source lang="bash"> # Upgrade sudo npm instal...")
 
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
[[Npm]] is Node Package Manager, a tool to install Node.js package.
[[npm]] is dependency/package manager that comes with [[Node.js]] and allows to install packages both globally and locally.


== References ==
== References ==
Line 6: Line 6:
== Quickstart ==
== Quickstart ==
<source lang="bash">
<source lang="bash">
# Upgrade
# Upgrade npm
sudo npm install -g npm
sudo npm install -g npm

# Install all dependencies of new project / checked-out branch
# ... this align versions with those in package.json
npm ci

# Install (newer version) of packages referenced in package.json
npm install

# Add a new package
npm install PACKAGE

# Add a new package, as development dependency (eg. test framework)
npm install -D typescript

# Install package globally
# ... usually not recommended since it breaks reproducibility.
# ... better use 'npx'
npm install -g PACKAGE

# Update dependency
npm update PACKAGE
</source>
</source>

== npx ==
'''npx''' is Node.js package runner. It either runs package from local {{file|node_modules/}} or from a global cache.

* https://www.freecodecamp.org/news/npm-vs-npx-whats-the-difference/

=== Install npx ===
Using npm, install globally (maybe only reason to install anything globally):
npm install -g npx

Or use [[Node.js|Nvm]].

Latest revision as of 12:06, 1 November 2021

npm is dependency/package manager that comes with Node.js and allows to install packages both globally and locally.

References

Quickstart

# Upgrade npm
sudo npm install -g npm

# Install all dependencies of new project / checked-out branch
# ... this align versions with those in package.json
npm ci

# Install (newer version) of packages referenced in package.json
npm install

# Add a new package
npm install PACKAGE

# Add a new package, as development dependency (eg. test framework)
npm install -D typescript

# Install package globally
# ... usually not recommended since it breaks reproducibility.
# ... better use 'npx'
npm install -g PACKAGE

# Update dependency
npm update PACKAGE

npx

npx is Node.js package runner. It either runs package from local node_modules/ or from a global cache.

Install npx

Using npm, install globally (maybe only reason to install anything globally):

npm install -g npx

Or use Nvm.