npm - node package manager
Muhammad Sadiq / August 07, 2022
If you don't know about npm or if you are new to javascript, i hope this will be super useful. If you already know about npm, may be you can jump to basic commands section
What is npm ?
Node Package Manager
In simpler terms, imagine you are a conducting a event. Now, if all information that you need about various activities for the event, are in different places, it would be little difficult to manage. Now, if same event has to be conducted at different places, this becomes way more complex and out of hand. What you need is to have all information about all activites and those needed for activities to complete in one place.
npm is just that and little bit more. Event is project and activities are libraries. As the name suggests it helps to manage all the libraries used in a project. It does 2 things, because of which it has become the most used in the javascript ecosystem.
-
First is the management of libraries that are used in project. When you use npm, it creates a file named
package.json
, where you can see all the libraries used in the project, in one place. -
Second is where the library(code) is coming from. Generally, unless explicitly specified, all the libraries that you install using npm are coming from
www.npmjs.com
which is owned by microsoft.
Similar package managers
yarn, pnpm etc are all package managers
But why ?
so that we dont have to store all library along with the project code, project code can be seperated from all the libraries aka dependencies. let me explain...
How do you install it ?
Check if you have installed it
npm --version :: should throw error if not installed and give version if installed correctly
Basic commands
npm --version
version of npm, that is installed
npm config list
lists all config that npm has collected, along with location from which it picked up the files
Advanced commands
npm ci
FAQ
Migrating from npm8 to npm 9
from npm 9 looks for auth details little differently. Any errors on unsupported auth config can be easily fixed using 'npm config fix'
your config should add the artifactory and auth for npm to work to authenticate properly
//yourorg.com/repository/:_auth=token
where token is a base64 of username:password
Note: // at the beginning is not comment and it is intentional