Before you can use the npm
command, you'll need to install Node.js.
You can install Node.js directly or to manage multiple versions, try Volta!
Before you can install packages in your current folder, you will need a package.json file. The easiest way to create one is to run npm init
, which starts a wizard with a series of prompts in your CLI (command line). Once you're finished, a package.json
will be created in the same directory.
If you want to install a package named foo
, simply run npm install foo
or npm i foo
. If foo
exists in the npm registry, it will install the package in ./node_modules/foo
and update package.json
with the version range that was installed:
"foo": "^1.2.3",
Additionally, a package-lock.json
file is created with the exact version that was installed. If someone were to join the project at a later time, they could simply run npm ci
to install the same exact versions that are specified in the package-lock.json
file. This ensures everyone is using the same version and you don't run into bugs that work fine on someone else's machine.
These versions follow Semantic Versioning.
TODO
npm ci
installs only the versions inpackage-lock.json
w/o updatingpackage.json
orpackage-lock.json
npm install
ornpm i
installs whatever dependencies are listed inpackage.json
and updates thepackage-lock.json
file accordingly (if there is a newer version within the range specified)npx foo
will look for./node_modules/.bin/foo
and run it if it exists- if it doesn't, it will install the latest version on the fly and run it
npm install -g foo
will installfoo
globally, regardless of what folder you're in- subsequently, running just
foo
from anywhere will runnode_modules/.bin/foo
in your global npm path