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 ciinstalls only the versions inpackage-lock.jsonw/o updatingpackage.jsonorpackage-lock.jsonnpm installornpm iinstalls whatever dependencies are listed inpackage.jsonand updates thepackage-lock.jsonfile accordingly (if there is a newer version within the range specified)npx foowill look for./node_modules/.bin/fooand run it if it exists- if it doesn't, it will install the latest version on the fly and run it
npm install -g foowill installfooglobally, regardless of what folder you're in- subsequently, running just
foofrom anywhere will runnode_modules/.bin/fooin your global npm path